Bug 34097 - TarInputStream.read() incorrectly returns signed values
Summary: TarInputStream.read() incorrectly returns signed values
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.5.4
Hardware: All All
: P2 normal (vote)
Target Milestone: 1.6.3
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2005-03-21 07:53 UTC by Ray Waldin
Modified: 2005-03-21 02:05 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ray Waldin 2005-03-21 07:53:54 UTC
Implementations of InputStream.read() are supposed to return a single unsigned
byte of content (that is, an integer in the range of 0 to 255 representing a
single byte), or -1 in the event the end of the stream is reached. 
TarInputStream.read() returns these bytes signed (that is integer values in the
range of -128 to 127).  This causes too many problems to list, but most
obviously, causes some streams to be closed prematurely due to -1 being returned
as content instead of 255.  

Below is a simple fix.

--- TarInputStream.java Tue Jan 11 18:41:21 2005
+++ TarInputStream.java Sun Mar 20 22:27:50 2005
@@ -291,13 +291,13 @@
     public int read() throws IOException {
         int num = this.read(this.oneBuf, 0, 1);
 
         if (num == -1) {
             return num;
         } else {
-            return (int) this.oneBuf[0];
+            return (this.oneBuf[0] + 256) & 0xFF;
         }
     }
Comment 1 Stefan Bodewig 2005-03-21 11:05:43 UTC
Strange that nobody has seen that before, probably everybody has been using the
array-arg methods.