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-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new d854da14 Stop BaseNCodecInputStream from reading after codec EOF
d854da14 is described below

commit d854da146789d18375648aad3d2aa910c65e154d
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Nov 21 13:40:50 2026 -0500

    Stop BaseNCodecInputStream from reading after codec EOF
    
    Drain buffered output without reading the source again, preventing
    lenient Base32 and Base64 decoding from blocking after padding.
    
    Add regression tests covering all five Base-N input streams, buffer
    boundaries, repeated EOF, open pipes, skipping, strict validation,
    and I/O failures.
    
    Update Javadoc
---
 src/changes/changes.xml                            |   1 +
 .../codec/binary/BaseNCodecInputStream.java        |  11 +-
 .../codec/binary/BaseNCodecInputStreamTest.java    | 420 +++++++++++++++++++++
 3 files changed, 429 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 199f3ddb..06b8e90c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Faris Basha TM, Gary 
Gregory">Javadoc: Fix dead Caverphone specification links.</action>      <!-- 
ADD -->
       <action type="fix" dev="ggregory" due-to="Palendromas1, Gary 
Gregory">Improve PercentCodec malformed-input and RFC1522Codec empty-content 
test coverage, and clarify PercentCodec thread-safety Javadoc (#459).</action>
       <action type="fix" dev="ggregory" due-to="simpleqt, Gary Gregory, Piotr 
P. Karwasz">GitIdentifiers: record files as regular without POSIX permissions 
(#458).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Stop 
BaseNCodecInputStream from reading the underlying stream after codec EOF, 
preventing unnecessary reads and blocking after padding in lenient Base32 and 
Base64 decoding.</action>
       <!-- ADD -->
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
org.apache.commons:commons-parent from 105 to 107.</action>
diff --git 
a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java 
b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
index c1c7e7ef..e2a90781 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
@@ -206,10 +206,15 @@ public class BaseNCodecInputStream<C extends BaseNCodec, 
T extends BaseNCodecInp
     /**
      * Attempts to read {@code len} bytes into the specified {@code b} array 
starting at {@code offset} from this InputStream.
      *
+     * <p>
+     * Buffered output remains readable after the codec reaches EOF. Once that 
output is drained, further nonempty reads return {@code -1} without reading
+     * the underlying stream again.
+     * </p>
+     *
      * @param array  destination byte array.
      * @param offset where to start writing the bytes.
      * @param len    maximum number of bytes to read.
-     * @return number of bytes read.
+     * @return The number of bytes read, or {@code -1} if EOF has been reached.
      * @throws IOException               Thrown if an I/O error occurs.
      * @throws NullPointerException      Thrown if the byte array parameter is 
null.
      * @throws IndexOutOfBoundsException Thrown if the offset, length, or 
buffer size is invalid.
@@ -234,8 +239,8 @@ public class BaseNCodecInputStream<C extends BaseNCodec, T 
extends BaseNCodecInp
          */
         // Attempt to read the request length
         while (readLen < len) {
-            if (!baseNCodec.hasData(context)) {
-                // Obtain more data.
+            if (!context.eof && !baseNCodec.hasData(context)) {
+                // Obtain more data only until the codec has reached EOF; 
buffered output is still drained below.
                 // buf is reused across calls to read to avoid repeated 
allocations
                 BaseNCodec.code(doEncode, baseNCodec, buf, 0, in.read(buf), 
context);
             }
diff --git 
a/src/test/java/org/apache/commons/codec/binary/BaseNCodecInputStreamTest.java 
b/src/test/java/org/apache/commons/codec/binary/BaseNCodecInputStreamTest.java
new file mode 100644
index 00000000..dbcd6674
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/codec/binary/BaseNCodecInputStreamTest.java
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.codec.binary;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.apache.commons.codec.CodecPolicy;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests EOF handling shared by all Base-N input streams.
+ */
+class BaseNCodecInputStreamTest {
+
+    /**
+     * Splits the input into bounded chunks and either reports physical EOF 
once or fails on any attempt to read beyond the supplied data.
+     */
+    private static final class EofTrackingInputStream extends InputStream {
+
+        private final byte[] data;
+
+        private final int chunkSize;
+
+        private final boolean allowEof;
+
+        private final IOException unexpectedRead = new IOException("Unexpected 
read beyond the supplied input");
+
+        private int position;
+
+        private int readCalls;
+
+        private int eofReturns;
+
+        private boolean closed;
+
+        EofTrackingInputStream(final byte[] data, final int chunkSize, final 
boolean allowEof) {
+            this.data = data;
+            this.chunkSize = chunkSize;
+            this.allowEof = allowEof;
+        }
+
+        @Override
+        public void close() {
+            closed = true;
+        }
+
+        @Override
+        public int read() throws IOException {
+            final byte[] one = new byte[1];
+            return read(one, 0, 1) == -1 ? -1 : one[0] & 0xff;
+        }
+
+        @Override
+        public int read(final byte[] buffer, final int offset, final int 
length) throws IOException {
+            if (length == 0) {
+                return 0;
+            }
+            readCalls++;
+            if (position == data.length) {
+                if (allowEof && eofReturns == 0) {
+                    eofReturns++;
+                    return -1;
+                }
+                throw unexpectedRead;
+            }
+            final int count = Math.min(Math.min(length, chunkSize), 
data.length - position);
+            System.arraycopy(data, position, buffer, offset, count);
+            position += count;
+            return count;
+        }
+    }
+
+    private static final int[] READ_SIZES = { -64, -3, 0, 1, 3, 64 };
+
+    /**
+     * EOF must be stable for all read and skip overloads, while zero-length 
reads and argument validation retain their normal behavior.
+     */
+    private static void assertFinished(final InputStream stream, final 
EofTrackingInputStream source) throws IOException {
+        final int calls = source.readCalls;
+        assertEquals(-1, stream.read());
+        assertEquals(-1, stream.read());
+        assertEquals(-1, stream.read(new byte[4]));
+        assertEquals(-1, stream.read(new byte[4], 1, 2));
+        assertEquals(0, stream.read(new byte[0]));
+        assertEquals(0, stream.read(new byte[4], 4, 0));
+        assertEquals(0, stream.skip(0));
+        assertEquals(0, stream.skip(Long.MAX_VALUE));
+        assertThrows(NullPointerException.class, () -> stream.read(null, 0, 
0));
+        assertThrows(IndexOutOfBoundsException.class, () -> stream.read(new 
byte[1], 2, 0));
+        assertThrows(IllegalArgumentException.class, () -> stream.skip(-1));
+        assertEquals(calls, source.readCalls, "EOF operations must not read 
from the source");
+        assertFalse(source.closed, "Reaching EOF must not close the source");
+    }
+
+    static Stream<Arguments> codecs() {
+        final List<Arguments> arguments = new ArrayList<>();
+        for (final CodecPolicy policy : CodecPolicy.values()) {
+            arguments.add(Arguments.of("Base16 " + policy, 
Base16.builder().setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base16 lower " + policy, 
Base16.builder().setLowerCase(true).setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base32 " + policy, 
Base32.builder().setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base32 hex " + policy, 
Base32.builder().setHexEncodeTable(true).setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base32 custom pad " + policy, 
Base32.builder().setPadding((byte) '.').setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base32 chunked " + policy, 
Base32.builder().setLineLength(16).setDecodingPolicy(policy).get()));
+            if (policy == CodecPolicy.STRICT) {
+                arguments.add(Arguments.of("Base45 " + policy, 
Base45.builder().setDecodingPolicy(policy).get()));
+            }
+            arguments.add(Arguments.of("Base58 " + policy, 
Base58.builder().setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base64 " + policy, 
Base64.builder().setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base64 URL " + policy, 
Base64.builder().setUrlSafe(true).setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base64 custom pad " + policy, 
Base64.builder().setPadding((byte) '.').setDecodingPolicy(policy).get()));
+            arguments.add(Arguments.of("Base64 chunked " + policy, 
Base64.builder().setLineLength(8).setDecodingPolicy(policy).get()));
+        }
+        return arguments.stream();
+    }
+
+    private static InputStream newStream(final InputStream source, final 
BaseNCodec codec, final boolean encode) {
+        if (codec instanceof Base16) {
+            return 
Base16InputStream.builder().setInputStream(source).setBaseNCodec((Base16) 
codec).setEncode(encode).get();
+        }
+        if (codec instanceof Base32) {
+            return 
Base32InputStream.builder().setInputStream(source).setBaseNCodec((Base32) 
codec).setEncode(encode).get();
+        }
+        if (codec instanceof Base45) {
+            return 
Base45InputStream.builder().setInputStream(source).setBaseNCodec((Base45) 
codec).setEncode(encode).get();
+        }
+        if (codec instanceof Base58) {
+            return 
Base58InputStream.builder().setInputStream(source).setBaseNCodec((Base58) 
codec).setEncode(encode).get();
+        }
+        if (codec instanceof Base64) {
+            return 
Base64InputStream.builder().setInputStream(source).setBaseNCodec((Base64) 
codec).setEncode(encode).get();
+        }
+        throw new IllegalArgumentException("Unknown codec: " + codec);
+    }
+
+    static Stream<Arguments> paddedCodecs() {
+        return Stream.of(Arguments.of("Base32", new Base32()), 
Arguments.of("Base32 hex", Base32.builder().setHexEncodeTable(true).get()),
+                Arguments.of("Base32 custom pad", 
Base32.builder().setPadding((byte) '.').get()), Arguments.of("Base64", new 
Base64()),
+                Arguments.of("Base64 custom pad", 
Base64.builder().setPadding((byte) '.').get()));
+    }
+
+    private static byte[] payload(final int length) {
+        final byte[] data = new byte[length];
+        for (int i = 0; i < length; i++) {
+            data[i] = (byte) (i * 31);
+        }
+        return data;
+    }
+
+    /**
+     * Zero selects single-byte reads, negative sizes select read(byte[]), and 
positive sizes select reads with a nonzero destination offset.
+     */
+    private static byte[] readAll(final InputStream stream, final int 
readSize) throws IOException {
+        final ByteArrayOutputStream output = new ByteArrayOutputStream();
+        if (readSize == 0) {
+            int value;
+            while ((value = stream.read()) != -1) {
+                output.write(value);
+            }
+        } else {
+            final byte[] buffer = new byte[readSize < 0 ? -readSize : readSize 
+ 2];
+            final int offset = readSize < 0 ? 0 : 1;
+            while (true) {
+                Arrays.fill(buffer, (byte) 0x5a);
+                final int count = readSize < 0 ? stream.read(buffer) : 
stream.read(buffer, offset, readSize);
+                if (readSize > 0) {
+                    assertEquals(0x5a, buffer[0]);
+                    assertEquals(0x5a, buffer[buffer.length - 1]);
+                }
+                if (count == -1) {
+                    break;
+                }
+                assertTrue(count > 0, "A nonempty read must return data or 
EOF");
+                output.write(buffer, offset, count);
+            }
+        }
+        return output.toByteArray();
+    }
+
+    static Stream<Arguments> strictInvalidInputs() {
+        final Base64 base64 = 
Base64.builder().setDecodingPolicy(CodecPolicy.STRICT).get();
+        final Base32 base32 = 
Base32.builder().setDecodingPolicy(CodecPolicy.STRICT).get();
+        return Stream.of(Arguments.of(base64, "Zg==A"), Arguments.of(base64, 
"Zg==!"), Arguments.of(base64, "Zg="), Arguments.of(base64, "Zh=="),
+                Arguments.of(base64, "Zm9vYg==A"), Arguments.of(base32, 
"MY======A"), Arguments.of(base32, "MY======!"), Arguments.of(base32, 
"MY====="),
+                Arguments.of(base32, "MZ======"), Arguments.of(base32, 
"MZXW6YTBOI======A"),
+                
Arguments.of(Base16.builder().setDecodingPolicy(CodecPolicy.STRICT).get(), 
"0"), Arguments.of(new Base45(), "0"),
+                Arguments.of(new Base58(), "0"));
+    }
+
+    static Stream<Arguments> strictStreamingCodecs() {
+        return codecs().filter(arguments -> {
+            final BaseNCodec codec = (BaseNCodec) arguments.get()[1];
+            return codec.isStrictDecoding() && (codec instanceof Base32 || 
codec instanceof Base64);
+        });
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("paddedCodecs")
+    void testLenientPaddingCanFinishWithoutOutput(final String name, final 
BaseNCodec codec) throws IOException {
+        for (final byte[] input : new byte[][] { { codec.pad }, { ' ', '\n', 
codec.pad } }) {
+            for (final int readSize : READ_SIZES) {
+                final EofTrackingInputStream source = new 
EofTrackingInputStream(input, 1, false);
+                try (InputStream stream = newStream(source, codec, false)) {
+                    assertArrayEquals(new byte[0], readAll(stream, readSize));
+                    assertFinished(stream, source);
+                }
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("paddedCodecs")
+    void testLenientPaddingDoesNotConsumeTheNextChunk(final String name, final 
BaseNCodec codec) throws IOException {
+        final byte[] decoded = payload(7);
+        final byte[] encoded = codec.encode(decoded);
+        final byte[] input = Arrays.copyOf(encoded, encoded.length + 1);
+        input[encoded.length] = '!';
+        final EofTrackingInputStream source = new 
EofTrackingInputStream(input, encoded.length, false);
+        try (InputStream stream = newStream(source, codec, false)) {
+            assertArrayEquals(decoded, readAll(stream, 64));
+            assertFinished(stream, source);
+            assertEquals(encoded.length, source.position);
+            assertEquals('!', source.read(), "The next chunk belongs to the 
caller");
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("paddedCodecs")
+    void testLenientPaddingDoesNotWaitForPipeToClose(final String name, final 
BaseNCodec codec) throws IOException {
+        final byte[] decoded = payload(7);
+        try (PipedInputStream source = new PipedInputStream();
+                PipedOutputStream writer = new PipedOutputStream(source);
+                InputStream stream = newStream(source, codec, false)) {
+            writer.write(codec.encode(decoded));
+            writer.flush();
+            // Keep the writer open until the decoder has returned all its 
output and EOF.
+            assertTimeoutPreemptively(Duration.ofSeconds(5), () -> {
+                assertArrayEquals(decoded, readAll(stream, 64));
+                assertEquals(-1, stream.read());
+            });
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("paddedCodecs")
+    void testLenientPaddingStopsAtEveryInputBoundary(final String name, final 
BaseNCodec codec) throws IOException {
+        // Cover every Base32 and Base64 partial-block size, with and without 
preceding complete blocks.
+        for (int length = 1; length <= 11; length++) {
+            final byte[] decoded = payload(length);
+            final byte[] encoded = codec.encode(decoded);
+            for (int pad = 0; pad < encoded.length; pad++) {
+                if (encoded[pad] != codec.pad) {
+                    continue;
+                }
+                // Lenient decoding ends at the first pad; no physical EOF or 
remaining padding may be requested.
+                final byte[] throughPad = Arrays.copyOf(encoded, pad + 1);
+                for (int chunkSize = 1; chunkSize <= throughPad.length; 
chunkSize++) {
+                    for (final int readSize : READ_SIZES) {
+                        final EofTrackingInputStream source = new 
EofTrackingInputStream(throughPad, chunkSize, false);
+                        try (InputStream stream = newStream(source, codec, 
false)) {
+                            assertArrayEquals(decoded, readAll(stream, 
readSize), name + ", length=" + length + ", chunk=" + chunkSize);
+                            assertFinished(stream, source);
+                            assertEquals(0, source.eofReturns);
+                        }
+                    }
+                }
+                break;
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("paddedCodecs")
+    void testReadAcrossInternalBufferBoundaries(final String name, final 
BaseNCodec codec) throws IOException {
+        for (final int length : new int[] { 4095, 4096, 4097, 8191, 8192, 8193 
}) {
+            final byte[] decoded = payload(length);
+            final byte[] encoded = codec.encode(decoded);
+            for (final boolean encode : new boolean[] { false, true }) {
+                final EofTrackingInputStream source = new 
EofTrackingInputStream(encode ? decoded : encoded, 8192, true);
+                try (InputStream stream = newStream(source, codec, encode)) {
+                    assertArrayEquals(encode ? encoded : decoded, 
readAll(stream, 333), name + ", length=" + length + ", encode=" + encode);
+                    assertFinished(stream, source);
+                }
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("codecs")
+    void testReadDoesNotRepeatPhysicalEof(final String name, final BaseNCodec 
codec) throws IOException {
+        for (final boolean encode : new boolean[] { false, true }) {
+            for (int length = 0; length <= 11; length++) {
+                final byte[] decoded = payload(length);
+                final byte[] encoded = codec.encode(decoded);
+                for (final int chunkSize : new int[] { 1, 7, 8192 }) {
+                    for (final int readSize : READ_SIZES) {
+                        final EofTrackingInputStream source = new 
EofTrackingInputStream(encode ? decoded : encoded, chunkSize, true);
+                        try (InputStream stream = newStream(source, codec, 
encode)) {
+                            assertEquals(0, stream.read(new byte[0]));
+                            assertEquals(0, stream.read(new byte[3], 1, 0));
+                            assertEquals(0, stream.skip(0));
+                            assertEquals(0, source.readCalls);
+                            assertArrayEquals(encode ? encoded : decoded, 
readAll(stream, readSize),
+                                    name + ", encode=" + encode + ", length=" 
+ length + ", chunk=" + chunkSize + ", read=" + readSize);
+                            assertFinished(stream, source);
+                            if (encode || codec.isStrictDecoding()) {
+                                assertEquals(1, source.eofReturns, "Encoding 
and strict decoding must reach physical EOF");
+                            }
+                        }
+                        assertTrue(source.closed, "Closing the wrapper must 
still close the source");
+                    }
+                }
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("codecs")
+    void testSkipPastEofDoesNotReadAgain(final String name, final BaseNCodec 
codec) throws IOException {
+        final byte[] decoded = payload(7);
+        final byte[] encoded = codec.encode(decoded);
+        for (final boolean encode : new boolean[] { false, true }) {
+            final byte[] expected = encode ? encoded : decoded;
+            final EofTrackingInputStream source = new 
EofTrackingInputStream(encode ? decoded : encoded, 1, true);
+            try (InputStream stream = newStream(source, codec, encode)) {
+                assertEquals(2, stream.skip(2));
+                assertEquals(expected[2] & 0xff, stream.read());
+                assertEquals(expected.length - 3, stream.skip(Long.MAX_VALUE));
+                assertFinished(stream, source);
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("codecs")
+    void testSourceFailureAfterPartialInputIsPropagated(final String name, 
final BaseNCodec codec) throws IOException {
+        // Fifteen bytes form complete Base32 and Base64 blocks, so lenient 
decoders cannot finish early at padding.
+        final byte[] decoded = payload(15);
+        final byte[] encoded = codec.encode(decoded);
+        for (final boolean encode : new boolean[] { false, true }) {
+            for (final int readSize : new int[] { 0, 64 }) {
+                final EofTrackingInputStream source = new 
EofTrackingInputStream(encode ? decoded : encoded, 2, false);
+                try (InputStream stream = newStream(source, codec, encode)) {
+                    assertSame(source.unexpectedRead, 
assertThrows(IOException.class, () -> readAll(stream, readSize)));
+                }
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("codecs")
+    void testSourceFailureBeforeEofIsPropagated(final String name, final 
BaseNCodec codec) throws IOException {
+        for (final boolean encode : new boolean[] { false, true }) {
+            final EofTrackingInputStream source = new 
EofTrackingInputStream(new byte[0], 1, false);
+            try (InputStream stream = newStream(source, codec, encode)) {
+                assertSame(source.unexpectedRead, 
assertThrows(IOException.class, stream::read));
+            }
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("strictInvalidInputs")
+    void testStrictDecodingStillRejectsTrailingInput(final BaseNCodec codec, 
final String input) throws IOException {
+        final byte[] encoded = StringUtils.getBytesUsAscii(input);
+        for (int chunkSize = 1; chunkSize <= encoded.length; chunkSize++) {
+            for (final int readSize : READ_SIZES) {
+                final EofTrackingInputStream source = new 
EofTrackingInputStream(encoded, chunkSize, true);
+                try (InputStream stream = newStream(source, codec, false)) {
+                    final IOException failure = 
assertThrows(IOException.class, () -> readAll(stream, readSize), input);
+                    assertTrue(failure.getCause() instanceof 
IllegalArgumentException, "The codec must reject the input, not reread physical 
EOF");
+                }
+            }
+        }
+    }
+
+    @ParameterizedTest(name = "{0}")
+    @MethodSource("strictStreamingCodecs")
+    void testStrictDecodingStillRequiresPhysicalEof(final String name, final 
BaseNCodec codec) throws IOException {
+        final byte[] encoded = codec.encode(payload(7));
+        for (int chunkSize = 1; chunkSize <= encoded.length; chunkSize++) {
+            final EofTrackingInputStream source = new 
EofTrackingInputStream(encoded, chunkSize, false);
+            try (InputStream stream = newStream(source, codec, false)) {
+                assertSame(source.unexpectedRead, 
assertThrows(IOException.class, () -> readAll(stream, 64)));
+            }
+        }
+    }
+}

Reply via email to