Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-6

[compress] TarOutputStream.java long file name bug (and fix!)

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Operating System: other
      Platform: All

    • 30495

    Description

      'LongLink' entries written to a tar file header by
      TarOutputStream.putNextEntry() specify the wrong file name length and data,
      preventing GNU tar from properly reading long file name entries (in the current
      GNU 'tar' implementation, sometimes one gets lucky and the entry happens to be
      null-terminated so it works anyway). In particular, the file name
      length-stored as an octal string in each header entry-should include an extra
      byte for the null terminator that must also be written at the end of the file
      name in the header.

      Here's what the code in
      org.apache.commons.compress.tar.TarOutputStream.putNextEntry() currently looks
      like (starting around line 424):

      if( m_longFileMode == LONGFILE_GNU ) {
      // create a TarEntry for the LongLink, the contents
      // of which are the entry's name
      final TarEntry longLinkEntry =
      new TarEntry( TarConstants.GNU_LONGLINK,
      TarConstants.LF_GNUTYPE_LONGNAME );

      longLinkEntry.setSize( entry.getName().length() );
      putNextEntry( longLinkEntry );
      write( entry.getName().getBytes() );
      //write( 0 );
      closeEntry();
      }

      Here's what the code should have been:

      if( m_longFileMode == LONGFILE_GNU ) {
      // create a TarEntry for the LongLink, the contents
      // of which are the entry's name
      final TarEntry longLinkEntry =
      new TarEntry( TarConstants.GNU_LONGLINK,
      TarConstants.LF_GNUTYPE_LONGNAME );

      longLinkEntry.setSize( entry.getName().length() + 1 );
      putNextEntry( longLinkEntry );
      write( entry.getName().getBytes() );
      write( 0 );
      closeEntry();
      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            tcurdt Torsten Curdt
            dyamasak@aol.com Derc Yamasaki
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment