diff options
author | Bruce Momjian <bruce@momjian.us> | 2001-05-16 03:29:01 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2001-05-16 03:29:01 +0000 |
commit | e046e1dfab4f62e24f1abbff7757b0d89620f225 (patch) | |
tree | 1e447636f1406339b01e1e86dd3ddab7b33d58dd /src | |
parent | dbb219b896fd0c0b4a00e4a0421f7b8b382fd968 (diff) | |
download | postgresql-e046e1dfab4f62e24f1abbff7757b0d89620f225.tar.gz postgresql-e046e1dfab4f62e24f1abbff7757b0d89620f225.zip |
The current implementation of BlobInputStream does
not properly handle 8-bit unsigned data as it blindly
casts the byte to an int, which java most helpfully
promotes to a signed type. This causes problems when
you can only return -1 to indicated EOF.
The following patch fixes the bug and has been tested
locally on image data.
Chad David
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java b/src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java index 646ea970052..9a4b67dec66 100644 --- a/src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java +++ b/src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java @@ -58,16 +58,24 @@ public class BlobInputStream extends InputStream { */ public int read() throws java.io.IOException { try { - if(buffer==null || bpos>=buffer.length) { + if (buffer == null || bpos >= buffer.length) { buffer=lo.read(bsize); bpos=0; } // Handle EOF - if(bpos>=buffer.length) + if(bpos >= buffer.length) { return -1; + } + + int ret = (buffer[bpos] & 0x7F); + if ((buffer[bpos] &0x80) == 0x80) { + ret |= 0x80; + } - return (int) buffer[bpos++]; + bpos++; + + return ret; } catch(SQLException se) { throw new IOException(se.toString()); } @@ -152,5 +160,4 @@ public class BlobInputStream extends InputStream { public boolean markSupported() { return true; } - -}
\ No newline at end of file +} |