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

TarArchiveInputStream does not properly read from underlying InputStream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.6
    • 1.7
    • Archivers
    • None

    Description

      TarArchiveInputStream reads header with its protected function readRecord(). This code improperly assumes that is.read(buf) always fills the whole buffer. This assumption is wrong. A proper implementation needs to call read multiple times until all bytes are read:

      TarArchiveInputStream.java
        protected byte[] readRecord() throws IOException {
              byte[] record = new byte[recordSize];
      
              // start change
              // int readNow = is.read(buf);
              int readNow = 0;
              while(readNow < recordSize){
                int bytesRead = is.read(record,0, recordSize - readNow);
                if(bytesRead == -1) {
                  break;
                }
                readNow += bytesRead;
              }
              // end change
              count(readNow);
              if (readNow != recordSize) {
                  return null;
              }
      
              return record;
          }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pavkovic Ilja Pavkovic
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: