![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
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. |
#2
| |||
| |||
|
|
On Wed, 7 Jan 2004, Martin Holz wrote: 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. Yes, it can even return 0 bytes if it feels like it. |
|
The odd thing about the javadocs is that they say "The data will be read from the stream as needed until end-of-file is reached." The length parameter's comment is "the number of bytes in the stream." |
|
This is strange because it seems to imply that the length argument is just for informational purposes and should not be used to limit the amount of data actually read from the stream. |
#3
| |||
| |||
|
|
On Wed, 7 Jan 2004, Martin Holz wrote: 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. Yes, it can even return 0 bytes if it feels like it. 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. The odd thing about the javadocs is that they say "The data will be read from the stream as needed until end-of-file is reached." The length parameter's comment is "the number of bytes in the stream." |
|
This is strange because it seems to imply that the length argument is just for informational purposes and should not be used to limit the amount of data actually read from the stream. |
#4
| |||
| |||
|
|
I was referring to the documentation for setBinaryStream. You mentioned that it should throw an Exception if it couldn't read "length" bytes from the stream. I was commenting that our implementation might be wrong by checking the length at all. |
#5
| |||
| |||
|
|
On Wed, 7 Jan 2004, Martin Holz wrote: 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. I have applied a version of this patch to the cvs version on gborg. The setAsciiStream and setUnicodeStream methods also had this problem. |
|
Your patch was not quite right because it didn't correctly handle the situation where the Stream was longer than the given length. You are right. |
#6
| |||
| |||
|
|
Kris Jurka <books (AT) ejurka (DOT) com> writes: On Wed, 7 Jan 2004, Martin Holz wrote: 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. I have applied a version of this patch to the cvs version on gborg. The setAsciiStream and setUnicodeStream methods also had this problem. Thank you. Why does it not show up at http://developer.postgresql.org/cvsw...Statement.java ? |
![]() |
| Thread Tools | |
| Display Modes | |
| |