Commons Compress
  1. Commons Compress
  2. COMPRESS-23

[compress] TarInputStream returns negative value for read() [PATCH]

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      TarInputStream.read() does not convert the byte it has read to a positive number
      after casting it to an integer. This causes downstream processes to fail to
      recognise the value properly.

      Index: org/apache/commons/compress/tar/TarInputStream.java
      ===================================================================
      — org/apache/commons/compress/tar/TarInputStream.java (revision 231420)
      +++ org/apache/commons/compress/tar/TarInputStream.java (working copy)
      @@ -306,7 +306,7 @@
      }
      else

      { - return (int)m_oneBuf[ 0 ]; + return (int)m_oneBuf[ 0 ] & 0xFF; }

      }

        Issue Links

          Activity

          Hide
          Mario Ivankovits added a comment -

          When will this fail?
          Do you have such a tar-file.

          Show
          Mario Ivankovits added a comment - When will this fail? Do you have such a tar-file.
          Hide
          Adrian Pronk added a comment -

          Create a file like this:
          $ perl -e 'print "\xff"' > negative-byte
          $ tar cf negative-byte.tar negative-byte

          Then run the following Java program:

          import org.apache.commons.compress.tar.TarInputStream;
          import org.apache.commons.compress.tar.TarEntry;
          import java.io.FileInputStream;

          public class TarPlay {
          public static void main(String[] args) throws Exception

          { TarInputStream tis = new TarInputStream(new FileInputStream("negative-byte.tar")); TarEntry tar = tis.getNextEntry(); System.out.println("Name: " + tar.getName() + ", size: " + tar.getSize()); int data = tis.read(); if (data == -1) System.out.println("EOF when trying to read first byte"); else System.out.println("Read first byte: " + data); }

          }

          This will output:
          Name: negative-byte, size: 1
          EOF when trying to read first byte

          Show
          Adrian Pronk added a comment - Create a file like this: $ perl -e 'print "\xff"' > negative-byte $ tar cf negative-byte.tar negative-byte Then run the following Java program: import org.apache.commons.compress.tar.TarInputStream; import org.apache.commons.compress.tar.TarEntry; import java.io.FileInputStream; public class TarPlay { public static void main(String[] args) throws Exception { TarInputStream tis = new TarInputStream(new FileInputStream("negative-byte.tar")); TarEntry tar = tis.getNextEntry(); System.out.println("Name: " + tar.getName() + ", size: " + tar.getSize()); int data = tis.read(); if (data == -1) System.out.println("EOF when trying to read first byte"); else System.out.println("Read first byte: " + data); } } This will output: Name: negative-byte, size: 1 EOF when trying to read first byte
          Hide
          Matt Benson added a comment -
              • COM-1778 has been marked as a duplicate of this bug. ***
          Show
          Matt Benson added a comment - COM-1778 has been marked as a duplicate of this bug. ***

            People

            • Assignee:
              Torsten Curdt
              Reporter:
              Adrian Pronk
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development