This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 14f93146e9 Deprecate RLEDecompressingInputStream.decompress (#1567)
14f93146e9 is described below
commit 14f93146e94fde3649d6d9d35b47031bdb35d22a
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Nov 12 02:38:03 2026 +0100
Deprecate RLEDecompressingInputStream.decompress (#1567)
The static decompress methods decompress MS-OVBA data in full with no
limit on the output size. Document that, and deprecate them for removal
in 7.0.0 in favour of reading the stream with a size limit.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../poi/util/RLEDecompressingInputStream.java | 36 ++++++++++++++++++++++
.../poi/util/TestRLEDecompressingInputStream.java | 18 +++++++----
2 files changed, 48 insertions(+), 6 deletions(-)
diff --git
a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
index 697c7e536e..41e2150571 100644
--- a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
+++ b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
@@ -296,10 +296,46 @@ public class RLEDecompressingInputStream extends
InputStream {
return (b0 & 0xFF) | ((b1 & 0xFF) << 8) | ((b2 & 0xFF) << 16) | ((b3 &
0xFF) << 24);
}
+ /**
+ * Decompresses the given MS-OVBA compressed data in full.
+ * <p>
+ * There is no limit on the size of the decompressed data, which can be
several hundred times
+ * the size of the compressed data, and all of it is held in memory.
+ *
+ * @param compressed the compressed data, starting with the signature byte
+ * @return the decompressed data
+ * @throws IOException if the data cannot be read
+ * @throws IllegalArgumentException if the signature byte or a chunk
header is invalid
+ * @throws IllegalStateException if the compressed data is invalid
+ * @deprecated POI 6.0.1, there is no limit on the size of the
decompressed data. Use
+ * {@link #RLEDecompressingInputStream(InputStream)} and read it with a
size limit instead,
+ * e.g. with {@link IOUtils#toByteArrayWithMaxLength(InputStream, int)}.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static byte[] decompress(byte[] compressed) throws IOException {
return decompress(compressed, 0, compressed.length);
}
+ /**
+ * Decompresses part of the given array of MS-OVBA compressed data in full.
+ * <p>
+ * There is no limit on the size of the decompressed data, which can be
several hundred times
+ * the size of the compressed data, and all of it is held in memory.
+ *
+ * @param compressed the array holding the compressed data
+ * @param offset the position in {@code compressed} of the signature byte
+ * @param length the number of bytes of compressed data, including the
signature byte
+ * @return the decompressed data
+ * @throws IOException if the data cannot be read
+ * @throws IllegalArgumentException if the signature byte or a chunk
header is invalid
+ * @throws IllegalStateException if the compressed data is invalid
+ * @deprecated POI 6.0.1, there is no limit on the size of the
decompressed data. Use
+ * {@link #RLEDecompressingInputStream(InputStream)} and read it with a
size limit instead,
+ * e.g. with {@link IOUtils#toByteArrayWithMaxLength(InputStream, int)}.
+ */
+ @Deprecated
+ @Removal(version = "7.0.0")
public static byte[] decompress(byte[] compressed, int offset, int length)
throws IOException {
try (UnsynchronizedByteArrayOutputStream out =
UnsynchronizedByteArrayOutputStream.builder().get();
InputStream instream =
UnsynchronizedByteArrayInputStream.builder().setByteArray(compressed).setOffset(offset).setLength(length).get();
diff --git
a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
index 1933440c7f..96ae41869e 100644
--- a/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
+++ b/poi/src/test/java/org/apache/poi/util/TestRLEDecompressingInputStream.java
@@ -143,7 +143,7 @@ class TestRLEDecompressingInputStream {
final byte[] compressed = {
0x01, 0x03, (byte)0xB0, 0x02, 0x61, 0x45, 0x00
};
- final byte[] expanded =
RLEDecompressingInputStream.decompress(compressed);
+ final byte[] expanded = decompressAll(compressed);
final byte[] expected =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".getBytes(StringUtil.UTF8);
assertArrayEquals(expected, expanded);
}
@@ -187,7 +187,7 @@ class TestRLEDecompressingInputStream {
final byte[] compressed = {
0x01, 0x02, (byte)0xB0, 0x01, 0x00, 0x00
};
- assertThrows(IllegalStateException.class, () ->
RLEDecompressingInputStream.decompress(compressed));
+ assertThrows(IllegalStateException.class, () ->
decompressAll(compressed));
}
/**
@@ -199,7 +199,7 @@ class TestRLEDecompressingInputStream {
final byte[] compressed = {
0x01, 0x03, (byte)0xB0, 0x02, 0x41, (byte)0xFF, 0x0F
};
- assertThrows(IllegalStateException.class, () ->
RLEDecompressingInputStream.decompress(compressed));
+ assertThrows(IllegalStateException.class, () ->
decompressAll(compressed));
}
/**
@@ -213,13 +213,13 @@ class TestRLEDecompressingInputStream {
};
final byte[] expected = new byte[4096];
Arrays.fill(expected, (byte) 0x41);
- assertArrayEquals(expected,
RLEDecompressingInputStream.decompress(full));
+ assertArrayEquals(expected, decompressAll(full));
// the same chunk followed by the literal 'B'
final byte[] overflow = {
0x01, 0x04, (byte)0xB0, 0x02, 0x41, (byte)0xFC, 0x0F, 0x42
};
- assertThrows(IllegalStateException.class, () ->
RLEDecompressingInputStream.decompress(overflow));
+ assertThrows(IllegalStateException.class, () ->
decompressAll(overflow));
}
/**
@@ -297,7 +297,13 @@ class TestRLEDecompressingInputStream {
final byte[] compressed = {
0x01, 0x02, 0x30, 0x61, 0x62, 0x63
};
- assertThrows(IllegalStateException.class, () ->
RLEDecompressingInputStream.decompress(compressed));
+ assertThrows(IllegalStateException.class, () ->
decompressAll(compressed));
+ }
+
+ private static byte[] decompressAll(byte[] compressed) throws IOException {
+ try (InputStream stream = new RLEDecompressingInputStream(new
ByteArrayInputStream(compressed))) {
+ return IOUtils.toByteArray(stream);
+ }
}
private static void checkRLEDecompression(String expected, byte[]
runLengthEncodedData) throws IOException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]