diff options
author | Damjan Jovanovic <damjan@apache.org> | 2022-10-16 18:31:15 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-03-20 14:43:13 +0000 |
commit | d0159892793860e53ddc068b4bdb707a521def19 (patch) | |
tree | 6be613bd1259a57d6ded677f49204af808fefe3e /scripting | |
parent | 9b631efd012c94d099b0181c5d85aed321d031f5 (diff) |
Fix some errors in the scripting module's XInputStreamImpl:
- Check the loop termination in readBytes() properly: currently it increments
totalBytesRead while also decrementing nBytesToRead, so when compared to
each other, the loop terminates when the buffer is half full. Only check
for nBytesToRead instead.
- Deal with the possibility of available() returning 0 in readSomeBytes().
Patch by: me
Cherry-picked from
https://github.com/apache/openoffice/commit/7e29bacc90c4b1b9788c3b71dfacd17daecde7a7
"Fix some errors in the scripting module's XInputStreamImpl:"
Change-Id: I951dc10565afa3519b0ddf98de559a7b585b1627
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149156
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java b/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java index 8320b6227cdb..3270d40d5bfb 100644 --- a/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java +++ b/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java @@ -41,11 +41,16 @@ public class XInputStreamImpl implements XInputStream { try { int bytesRead; - while ((bytesRead = is.read(aData[ 0 ], totalBytesRead, nBytesToRead)) > 0 - && (totalBytesRead < nBytesToRead)) { + while (( nBytesToRead > 0 ) && (bytesRead = is.read(aData[ 0 ], totalBytesRead, nBytesToRead)) > 0) { totalBytesRead += bytesRead; nBytesToRead -= bytesRead; } + if ( totalBytesRead < aData[ 0 ].length ) + { + byte[] out = new byte[ totalBytesRead ]; + System.arraycopy( aData[ 0 ], 0, out, 0, totalBytesRead ); + aData[ 0 ] = out; + } } catch (IOException e) { throw new com.sun.star.io.IOException(e); } catch (IndexOutOfBoundsException aie) { @@ -62,7 +67,8 @@ public class XInputStreamImpl implements XInputStream { int bytesToRead = nMaxBytesToRead; int availableBytes = available(); - if (availableBytes < nMaxBytesToRead) { + if (0 < availableBytes && availableBytes < nMaxBytesToRead) + { bytesToRead = availableBytes; } |