dbTalk Databases Forums  

[BUGS] jdbc1.AbstractJdbc1Statement.setBinaryStream bug and patch

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] jdbc1.AbstractJdbc1Statement.setBinaryStream bug and patch in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Martin Holz
 
Posts: n/a

Default [BUGS] jdbc1.AbstractJdbc1Statement.setBinaryStream bug and patch - 01-07-2004 , 12:47 PM






--Boundary-00=_B/E//FHYB/2qMo/
Content-Type: text/plain;
charset="iso-8859-15"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Hello,

org.postgresql.jdbc1.AbstractJdbc1Statement.setBin aryStream()
in postgresql 7.4.1 wrongly assumes, that
java.io.InputStream.read(byte[] b,int offset,int len )
will always read len bytes. InputStream only guarantees to
return at least 1 byte per call. The attached patch solves the bug.

Btw. setBinaryStream() should really throw an SQLException, if
in can not read as many bytes as expected from the InputStream.
Otherwise the application might silently loss data.

Regards
Martin

--
Martin Holz <holz (AT) fiz-chemie (DOT) de>

Softwareentwicklung / Vernetztes Studium - Chemie
FIZ CHEMIE Berlin
Franklin Str. 11
D-10587 Berlin


--Boundary-00=_B/E//FHYB/2qMo/
Content-Type: text/x-diff;
charset="us-ascii";
name="AbstractJdbc1Statement.java.diff"
Content-Disposition: attachment; filename="AbstractJdbc1Statement.java.diff"
Content-Transfer-Encoding: 7bit

*** AbstractJdbc1Statement.java.orig 2004-01-07 14:09:31.000000000 +0100
--- AbstractJdbc1Statement.java 2004-01-07 14:21:28.000000000 +0100
***************
*** 1466,1477 ****
//handling very large values. Thus the implementation ends up calling
//setBytes() since there is no current way to stream the value to the server
byte[] l_bytes = new byte[length];
! int l_bytesRead;
! try
{
! l_bytesRead = x.read(l_bytes, 0, length);
! }
! catch (IOException l_ioe)
{
throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
}
--- 1466,1482 ----
//handling very large values. Thus the implementation ends up calling
//setBytes() since there is no current way to stream the value to the server
byte[] l_bytes = new byte[length];
! int l_bytesRead = 0;
! try
{
! while (true)
! {
! int n = x.read(l_bytes, l_bytesRead, length - l_bytesRead);
! if (n == -1) break;
! l_bytesRead += n;
! }
!
! } catch (IOException l_ioe)
{
throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR, l_ioe);
}

--Boundary-00=_B/E//FHYB/2qMo/
Content-Type: text/plain
Content-Disposition: inline
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

--Boundary-00=_B/E//FHYB/2qMo/--

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.