You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Florian (Jira)" <ji...@apache.org> on 2022/06/12 00:29:00 UTC

[jira] [Commented] (CODEC-305) unfinished bytes break base16 input stream

    [ https://issues.apache.org/jira/browse/CODEC-305?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17553196#comment-17553196 ] 

Florian commented on CODEC-305:
-------------------------------

Submitted a pull request with a fix here: [https://github.com/apache/commons-codec/pull/135]

> unfinished bytes break base16 input stream
> ------------------------------------------
>
>                 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
>
> 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)