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

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d6b112ba AbstractLZ77CompressorInputStream now throws 
ArchiveException instead of IllegalArgumentException.
8d6b112ba is described below

commit 8d6b112baff3f65261f0a491c1422fc104c204d2
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Aug 11 07:17:05 2026 -0400

    AbstractLZ77CompressorInputStream now throws ArchiveException instead of
    IllegalArgumentException.
---
 src/changes/changes.xml                            |  3 ++-
 .../lz4/BlockLZ4CompressorInputStream.java         |  3 ++-
 .../AbstractLZ77CompressorInputStream.java         | 26 +++++++++++-----------
 .../AbstractLZ77CompressorInputStreamTest.java     | 12 ++++++----
 4 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b68cd0de8..9206ad221 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -146,7 +146,8 @@ The <action> type attribute can be add,update,fix,remove.
       <!-- FIX deflate64 -->
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">Reject invalid literal/length and distance codes in Deflate64 decoder 
(#785).</action>
       <!-- FIX lz77 -->
-      <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">Reject back-reference offset larger than the window in lz77 decoder 
(#797).</action>
+      <action type="fix" dev="ggregory" due-to="KALI 834X, Gary 
Gregory">[LZ77] Reject back-reference offset larger than the window in lz77 
decoder class AbstractLZ77CompressorInputStream (#797).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] 
AbstractLZ77CompressorInputStream now throws ArchiveException instead of 
IllegalArgumentException.</action>
       <!-- FIX general -->      
       <action type="fix" dev="ggregory" due-to="Piotr P. Karwasz, Gary 
Gregory">Add missing Javadoc @since tag to 
org.apache.commons.compress.compressors.lz77support.LZ77Compressor.AbstractReference.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Classes in 
org.apache.commons.compress.archivers now throw a subclass of IOException 
called ArchiveException instead of IOException when a formatting problem is 
found.</action>
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
index 0ed2c5e15..8b8d439d7 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
@@ -55,8 +55,9 @@ private enum State {
      * Creates a new LZ4 input stream.
      *
      * @param is An InputStream to read compressed data from.
+     * @throws CompressorException if windowSize is not positive.
      */
-    public BlockLZ4CompressorInputStream(final InputStream is) {
+    public BlockLZ4CompressorInputStream(final InputStream is) throws 
CompressorException {
         super(is, WINDOW_SIZE);
     }
 
diff --git 
a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
 
b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
index 21c7ad0ed..7a984efe3 100644
--- 
a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
@@ -115,12 +115,12 @@ public abstract class AbstractLZ77CompressorInputStream 
extends CompressorInputS
      *
      * @param is         An InputStream to read compressed data from.
      * @param windowSize Size of the window kept for back-references, must be 
bigger than the biggest offset expected.
-     * @throws IllegalArgumentException if windowSize is not bigger than 0.
+     * @throws CompressorException if windowSize is not positive.
      */
-    public AbstractLZ77CompressorInputStream(final InputStream is, final int 
windowSize) {
+    public AbstractLZ77CompressorInputStream(final InputStream is, final int 
windowSize) throws CompressorException {
         this.in = 
BoundedInputStream.builder().setInputStream(is).asSupplier().get();
         if (windowSize <= 0) {
-            throw new IllegalArgumentException("windowSize must be bigger than 
0");
+            throw new CompressorException("windowSize must be positive.");
         }
         this.windowSize = windowSize;
         buf = new byte[3 * windowSize];
@@ -175,11 +175,11 @@ protected final boolean hasMoreDataInBlock() {
      * </p>
      *
      * @param data The data to fill the window with.
-     * @throws IllegalStateException if the stream has already started to read 
data.
+     * @throws CompressorException if the stream has already started to read 
data.
      */
-    public void prefill(final byte[] data) {
+    public void prefill(final byte[] data) throws CompressorException {
         if (writeIndex != 0) {
-            throw new IllegalStateException("The stream has already been read 
from, can't prefill anymore");
+            throw new CompressorException("The stream has already been read 
from, can't prefill anymore");
         }
         // we don't need more data than the big offset could refer to, so cap 
it
         final int len = Math.min(windowSize, data.length);
@@ -271,17 +271,17 @@ private void slideBuffer() {
      *
      * @param offset The offset of the back-reference.
      * @param length The length of the back-reference.
-     * @throws IllegalArgumentException if offset not bigger than 0, bigger 
than the window size or bigger than the number of bytes available for 
back-references,
+     * @throws CompressorException if offset not bigger than 0, bigger than 
the window size or bigger than the number of bytes available for 
back-references,
      *                                  or if length is negative.
      */
-    protected final void startBackReference(final int offset, final long 
length) {
+    protected final void startBackReference(final int offset, final long 
length) throws CompressorException {
         // An offset larger than windowSize can't be honored: the buffer only 
keeps windowSize bytes of history, so once the buffer is slid mid-copy the 
source
         // index writeIndex - offset in tryToCopy would turn negative.
         if (offset <= 0 || offset > writeIndex || offset > windowSize) {
-            throw new IllegalArgumentException("offset must be bigger than 0 
but not bigger than the window size or the number of bytes available for 
back-references");
+            throw new CompressorException("offset must be bigger than 0 but 
not bigger than the window size or the number of bytes available for 
back-references");
         }
         if (length < 0) {
-            throw new IllegalArgumentException("length must not be negative");
+            throw new CompressorException("length must not be negative");
         }
         backReferenceOffset = offset;
         bytesRemaining = length;
@@ -291,11 +291,11 @@ protected final void startBackReference(final int offset, 
final long length) {
      * Used by subclasses to signal the next block contains the given amount 
of literal data.
      *
      * @param length The length of the block.
-     * @throws IllegalArgumentException if length is negative.
+     * @throws CompressorException if length is negative.
      */
-    protected final void startLiteral(final long length) {
+    protected final void startLiteral(final long length) throws 
CompressorException {
         if (length < 0) {
-            throw new IllegalArgumentException("length must not be negative");
+            throw new CompressorException("length must not be negative");
         }
         bytesRemaining = length;
     }
diff --git 
a/src/test/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStreamTest.java
index 38d04ca6d..42fd1c7e0 100644
--- 
a/src/test/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStreamTest.java
@@ -26,20 +26,24 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.compress.compressors.CompressorException;
 import org.apache.commons.lang3.ArrayUtils;
 import org.junit.jupiter.api.Test;
 
+/**
+ * Tests {@link AbstractLZ77CompressorInputStream}.
+ */
 class AbstractLZ77CompressorInputStreamTest {
 
     private static final class TestStream extends 
AbstractLZ77CompressorInputStream {
 
         private boolean literal;
 
-        TestStream(final InputStream in) {
+        TestStream(final InputStream in) throws CompressorException {
             super(in, 1024);
         }
 
-        void literal(final int len) {
+        void literal(final int len) throws CompressorException {
             startLiteral(len);
             literal = true;
         }
@@ -60,7 +64,7 @@ void testBackReferenceOffsetLargerThanWindowIsRejected() 
throws IOException {
         try (TestStream s = new TestStream(new ByteArrayInputStream(data))) {
             s.literal(data.length);
             assertEquals(data.length, s.read(new byte[data.length]));
-            assertThrows(IllegalArgumentException.class, () -> 
s.startBackReference(1500, 4));
+            assertThrows(CompressorException.class, () -> 
s.startBackReference(1500, 4));
         }
     }
 
@@ -70,7 +74,7 @@ void testCantPrefillAfterDataHasBeenRead() throws IOException 
{
         try (TestStream s = new TestStream(new ByteArrayInputStream(data))) {
             s.literal(3);
             assertEquals(1, s.read());
-            assertThrows(IllegalStateException.class, () -> s.prefill(new 
byte[] { 1, 2, 3 }));
+            assertThrows(CompressorException.class, () -> s.prefill(new byte[] 
{ 1, 2, 3 }));
         }
     }
 

Reply via email to