You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2022/10/31 09:37:14 UTC
[openoffice] branch AOO41X updated: 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().
This is an automated email from the ASF dual-hosted git repository.
mseidel pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/AOO41X by this push:
new 4271e4a8d1 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().
4271e4a8d1 is described below
commit 4271e4a8d1fe4fd139f365686585a11457a0b972
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Oct 16 18:31:15 2022 +0200
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 commit 7e29bacc90c4b1b9788c3b71dfacd17daecde7a7)
---
.../com/sun/star/script/framework/io/XInputStreamImpl.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java b/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
index 4926ce8e45..a9c58f72ce 100644
--- a/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
+++ b/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
@@ -44,11 +44,17 @@ public class XInputStreamImpl implements XInputStream
try
{
int bytesRead = 0;
- 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 )
{
@@ -65,7 +71,7 @@ public class XInputStreamImpl implements XInputStream
{
int bytesToRead = nMaxBytesToRead;
int availableBytes = available();
- if ( availableBytes < nMaxBytesToRead )
+ if ( 0 < availableBytes && availableBytes < nMaxBytesToRead )
{
bytesToRead = availableBytes;
}