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/23 15:55:08 UTC

[openoffice] branch AOO42X updated: Fix the java.lang.NullPointerException in readBytes() and readSomeBytes() methods in InputStreamToXInputStreamAdapter when called from the inter-process UNO bridge.

This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/AOO42X by this push:
     new 70f819d9f3 Fix the java.lang.NullPointerException in readBytes() and readSomeBytes() methods in InputStreamToXInputStreamAdapter when called from the inter-process UNO bridge.
70f819d9f3 is described below

commit 70f819d9f3a13005440863f9fe2f410ce812cc02
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Oct 16 17:33:49 2022 +0200

    Fix the java.lang.NullPointerException in readBytes() and readSomeBytes() methods in
    InputStreamToXInputStreamAdapter when called from the inter-process UNO bridge.
    
    XInputStream::readBytes() documents how the buffer is an "out" parameter, and isn't passed
    to the implementing end, which is why we get the buffer as a "byte[][] b" and b[0] == null.
    Its role is to box a byte[] array to be returned the client. Thus, allocate the buffer if
    it is missing or too small.
    
    Additionally, virtually all other readBytes() and readSomeBytes() implementations trim this
    sequence to the actual number of bytes read. This presumably reduces the inter-process
    traffic, but some callers even rely on the sequence to be trimmed, eg.
    main/sax/source/expatwrap/xml2utf.cxx. Thus trim our returned array too.
    
    Patch by: me
    
    (cherry picked from commit 6cb06142790376a2c58e6392182eb071420a4221)
---
 .../uno/adapter/InputStreamToXInputStreamAdapter.java  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
index b111ba6728..c68c8be276 100644
--- a/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
+++ b/main/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
@@ -81,6 +81,9 @@ public class InputStreamToXInputStreamAdapter implements XInputStream {
         int count = 0;
         try {
 	    long bytesRead=0;
+            if (b[0] == null || b[0].length < len) {
+                b[0] = new byte[len];
+            }
 	    if (len >iIn.available()) {
 			bytesRead = iIn.read(b[0], 0, iIn.available());
 	    }
@@ -91,6 +94,12 @@ public class InputStreamToXInputStreamAdapter implements XInputStream {
             // only pass in an integer length to read, so the bytesRead 
             // must <= len.
             //
+            if (bytesRead < b[0].length) {
+                int outSize = bytesRead > 0 ? (int)bytesRead : 0;
+                byte[] out = new byte[outSize];
+                System.arraycopy(b[0], 0, out, 0, outSize);
+                b[0] = out;
+            }
             if (bytesRead <= 0) {
                 return(0);
 	    } 	    
@@ -108,6 +117,9 @@ public class InputStreamToXInputStreamAdapter implements XInputStream {
         int count = 0;
         try {
 	    long bytesRead=0;
+            if (b[0] == null || b[0].length < len) {
+                b[0] = new byte[len];
+            }
 	    if (len >iIn.available()) {
 			bytesRead = iIn.read(b[0], 0, iIn.available());
 	    }
@@ -118,6 +130,12 @@ public class InputStreamToXInputStreamAdapter implements XInputStream {
             // only pass in an integer length to read, so the bytesRead 
             // must <= len.
             //
+            if (bytesRead < b[0].length) {
+                int outSize = bytesRead > 0 ? (int)bytesRead : 0;
+                byte[] out = new byte[outSize];
+                System.arraycopy(b[0], 0, out, 0, outSize);
+                b[0] = out;
+            }
             if (bytesRead <= 0) {
                 return(0);
 	    }