Skip site navigation (1) Skip section navigation (2)

[PATCHES] BlobInputStream.java patch

From: Chad David <davidc(at)lodge(dot)guild(dot)ab(dot)ca>
To: pgsql-patches(at)postgresql(dot)org
Subject: [PATCHES] BlobInputStream.java patch
Date: 2001-02-22 18:25:41
Message-ID: 20010222112541.A31651@lodge.guild.ab.ca (view raw or flat)
Thread:
Lists: pgsql-jdbcpgsql-patches
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
Guild Software Inc.
davidc(at)guild(dot)ab(dot)ca


*** BlobInputStream.java    Thu Feb 22 11:11:23 2001
--- BlobInputStream.patched Thu Feb 22 11:10:38 2001
***************
*** 58,73 ****
     */
    public int read() throws java.io.IOException {
      try {
!       if(buffer==null || bpos>=buffer.length) {
          buffer=lo.read(bsize);
          bpos=0;
        }

        // Handle EOF
!       if(bpos>=buffer.length)
          return -1;

!       return (int) buffer[bpos++];
      } catch(SQLException se) {
        throw new IOException(se.toString());
      }
--- 58,81 ----
     */
    public int read() throws java.io.IOException {
      try {
!       if (buffer == null || bpos >= buffer.length) {
          buffer=lo.read(bsize);
          bpos=0;
        }

        // Handle EOF
!       if(bpos >= buffer.length) {
          return -1;
+       }

!       int ret = (buffer[bpos] & 0x7F);
!       if ((buffer[bpos] &0x80) == 0x80) {
!         ret |= 0x80;
!       }
!
!       bpos++;
!
!       return ret;
      } catch(SQLException se) {
        throw new IOException(se.toString());
      }
***************
*** 153,156 ****
    return true;
      }

! }
--- 161,164 ----
    return true;
      }

! }




--ELM989802762-2250-0_--

Responses

pgsql-patches by date

Next:From: Matthew KirkwoodDate: 2001-02-24 15:49:37
Subject: A patch for xlog.c
Previous:From: Tom LaneDate: 2001-02-22 04:12:47
Subject: Re: Re: Fixes to index pages

pgsql-jdbc by date

Next:From: Peter EisentrautDate: 2001-02-22 21:07:01
Subject: Java class documentation
Previous:From: Antonio FiolDate: 2001-02-22 17:10:52
Subject: [Fwd: JDBC Timestamp problem]

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group