diff options
author | Nico Kruber <[email protected]> | 2012-04-25 10:32:07 +0200 |
---|---|---|
committer | Nico Kruber <[email protected]> | 2012-06-13 18:05:59 +0200 |
commit | a963b819552657d9df0ffae7ee9d9143a5b319e5 (patch) | |
tree | 551e5997f108491d010a09e50a76aa34bed43ab3 /lib/jinterface | |
parent | 628d51fd2171cb6e8275f9a16d85300e42e83594 (diff) | |
download | otp-a963b819552657d9df0ffae7ee9d9143a5b319e5.tar.gz otp-a963b819552657d9df0ffae7ee9d9143a5b319e5.tar.bz2 otp-a963b819552657d9df0ffae7ee9d9143a5b319e5.zip |
fix reading compressed binary terms from Java
Larger compressed binary could not be decoded inside JInterface.
- applied a patch posted on erlang-questins in September 2009
http://erlang.org/pipermail/erlang-patches/2009-September/000478.html
-> extended this patch as it alone was not enough to fix the bug
Problem was that when reading from an InputStream, you can only specify a maximum number of bytes to read. Java doesn't quarantee that it actually reads this many bytes - it could be less!
This patch now reads up until the expected size bytes. If there are more than expected, the actual number of available bytes is not printed (we probably shouldn't read the additional bytes, security-wise - the erlang external byte representation is broken in this case though).
Diffstat (limited to 'lib/jinterface')
-rw-r--r-- | lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java index b9b43481ee..ae5f4ee072 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java @@ -1112,12 +1112,16 @@ public class OtpInputStream extends ByteArrayInputStream { final int size = read4BE(); final byte[] buf = new byte[size]; final java.util.zip.InflaterInputStream is = - new java.util.zip.InflaterInputStream(this); + new java.util.zip.InflaterInputStream(this, new java.util.zip.Inflater(), size); + int curPos = 0; try { - final int dsize = is.read(buf, 0, size); - if (dsize != size) { + int curRead; + while(curPos < size && (curRead = is.read(buf, curPos, size - curPos)) != -1) { + curPos += curRead; + } + if (curPos != size) { throw new OtpErlangDecodeException("Decompression gave " - + dsize + " bytes, not " + size); + + curPos + " bytes, not " + size); } } catch (final IOException e) { throw new OtpErlangDecodeException("Cannot read from input stream"); |