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

TarArchiveInputStream fails to read PAX header from InputStream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.8
    • 1.8.1
    • Archivers

    Description

      We have a scenario with a "slow" InputStream and are facing IOExceptions with TarArchiveEntry#getNextTarEntry().

      If the InputStream does not deliver fast enough, TarArchiveEntry#parsePaxHeaders(InputStream i) fails at this location:

      TarArchiveInputStream.java
      // Get rest of entry
      byte[] rest = new byte[len - read];
      int got = i.read(rest);
      if (got != len - read){
      	throw new IOException("Failed to read "
      		+ "Paxheader. Expected "
      		+ (len - read)
      		+ " bytes, read "
      		+ got);
      }
      

      We would suggest to change the code to something like this:

      TarArchiveInputStream.java
      // Get rest of entry
      byte[] rest = new byte[len - read];
      int got = 0;
      while((ch = i.read()) != -1) {
      	rest[got] = (byte) ch;
      	got++;
      	if(got == len - read) {
      		break;
      	}
      }
      if (got != len - read){
      	throw new IOException("Failed to read "
      		+ "Paxheader. Expected "
      		+ (len - read)
      		+ " bytes, read "
      		+ got);
      }
      

      This would make sure, that it gets all bytes of the PAX header value.

      Attachments

        Activity

          People

            Unassigned Unassigned
            paburk Patrik Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: