You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2022/06/13 11:45:00 UTC
[jira] [Resolved] (CODEC-305) Base16InputStream skips characters
[ https://issues.apache.org/jira/browse/CODEC-305?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alex Herbert resolved CODEC-305.
--------------------------------
Fix Version/s: 1.16
Resolution: Fixed
Fixed in commit:
7ccbc3d0c39aaf49ff70f19d85f173f98550d0fb
> Base16InputStream skips characters
> ----------------------------------
>
> Key: CODEC-305
> URL: https://issues.apache.org/jira/browse/CODEC-305
> Project: Commons Codec
> Issue Type: Bug
> Affects Versions: 1.15
> Environment: adopt openjdk 11
> windows 10
> Reporter: Florian
> Priority: Major
> Fix For: 1.16
>
>
> If the read() method of the input stream which is wrapped by a Base16InputStream returns the following three arrays of data it will skip the last character of the second array:
> * array with an odd length (e.g. "010")
> * array with an even length (e.g "2030")
> * array with an odd length (e.g. "405")
> The above data should result in the following bytes [1, 2, 3, 4, 5], however
> * in lenient mode it reads [1, 2, 3, 64]
> * in strict mode it throws an IllegalArgumentException
> I have encountered this issue when reading from an java 11 http input stream. In order to test this easier I have created the following class to reproduce the issue:
> {code:java}
> public class TestInputStream extends InputStream {
> public static void main(String[] args) throws IOException {
> final Base16InputStream stream = new Base16InputStream(
> new TestInputStream(),
> false,
> true,
> CodecPolicy.STRICT
> );
> int value;
> while ((value = stream.read()) != -1) {
> System.out.println((byte) value);
> }
> }
> private int readCount = 0;
> @Override
> public int read() {
> return 0;
> }
> @Override
> public int read(byte[] output) {
> switch (readCount++) {
> case 0: return writeBytes(output, "010");
> case 1: return writeBytes(output, "2030");
> case 2: return writeBytes(output, "405");
> default: return -1;
> }
> }
> private static int writeBytes(byte[] output, String str) {
> final byte[] data = str.getBytes();
> System.arraycopy(data, 0, output, 0, data.length);
> return data.length;
> }
>
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)