summaryrefslogtreecommitdiff
path: root/ridljar
diff options
context:
space:
mode:
authorDamjan Jovanovic <damjan@apache.org>2023-02-27 20:15:20 +0000
committerCaolán McNamara <caolanm@redhat.com>2023-02-28 10:05:12 +0000
commit618e8e30a21efea41b9a4e63219de20e38987f4a (patch)
tree86341773b6700859ba2f2e211d857faccc697b96 /ridljar
parent4e6ab75c1a907398d24768d19cf097a4892d374c (diff)
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. (cherry-picked from 6cb06142790376a2c58e6392182eb071420a4221) Change-Id: I42eb209b68f7c13a34670d03c2ca61d76672385b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147933 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'ridljar')
-rw-r--r--ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
index a81bb85b1c57..d547b1e7ce17 100644
--- a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
+++ b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java
@@ -79,6 +79,9 @@ public final class InputStreamToXInputStreamAdapter implements XInputStream {
{
try {
long bytesRead;
+ 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());
}
@@ -89,6 +92,12 @@ public final class InputStreamToXInputStreamAdapter implements XInputStream {
// Casting bytesRead to an int is okay, since the user can
// 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;
}
@@ -103,6 +112,9 @@ public final class InputStreamToXInputStreamAdapter implements XInputStream {
{
try {
long bytesRead;
+ 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());
}
@@ -113,6 +125,12 @@ public final class InputStreamToXInputStreamAdapter implements XInputStream {
// Casting bytesRead to an int is okay, since the user can
// 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;
}