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

          Adrian Pronk created issue -
          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. ***
          Henri Yandell made changes -
          Field Original Value New Value
          issue.field.bugzillaimportkey 36243 12342489
          Henri Yandell made changes -
          Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
          Project Commons [ 12310458 ] Commons Sandbox [ 12310491 ]
          Affects Version/s 1.0 Alpha [ 12311665 ]
          Key COM-2337 SANDBOX-74
          Component/s Sandbox [ 12311131 ]
          Henri Yandell made changes -
          Affects Version/s 1.0 Alpha [ 12311727 ]
          Henri Yandell made changes -
          Component/s Compress [ 12311183 ]
          Torsten Curdt made changes -
          Assignee Torsten Curdt [ tcurdt ]
          Torsten Curdt made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          Dennis Lundberg made changes -
          Project Commons Sandbox [ 12310491 ] Commons Compress [ 12310904 ]
          Key SANDBOX-74 COMPRESS-23
          Component/s Compress [ 12311183 ]
          Adrian Pronk made changes -
          Link This issue is duplicated by COMPRESS-33 [ COMPRESS-33 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Closed Closed
          1237d 15h 43m 1 Torsten Curdt 07/Jan/09 13:59

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development