Repository: aries-rsa Updated Branches: refs/heads/master 4da8a0d4d -> c5b768f3d
remote inputstreams mangle the contents The InputStreamProxy broke data in the single byte read method by ignoring signed vs. unsigned. bytes need to be '& 0xFF'd before returning... Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/c5b768f3 Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/c5b768f3 Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/c5b768f3 Branch: refs/heads/master Commit: c5b768f3d15bfd484ce2ae42088e0d52e452f64d Parents: 4da8a0d Author: Johannes Utzig <jut...@apache.org> Authored: Fri Apr 13 16:39:56 2018 +0200 Committer: Johannes Utzig <jut...@apache.org> Committed: Fri Apr 13 16:41:54 2018 +0200 ---------------------------------------------------------------------- .../fastbin/streams/InputStreamProxy.java | 2 +- .../fastbin/streams/InputStreamProxyTest.java | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5b768f3/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxy.java ---------------------------------------------------------------------- diff --git a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxy.java b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxy.java index f9d9e2f..8ae1210 100644 --- a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxy.java +++ b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxy.java @@ -83,7 +83,7 @@ public class InputStreamProxy extends InputStream implements Serializable { //try again return read(); } - return buffer[position++]; + return (buffer[position++] & 0xFF); } private void fillBuffer() throws IOException { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5b768f3/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxyTest.java ---------------------------------------------------------------------- diff --git a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxyTest.java b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxyTest.java index 0abcdee..82ac9cf 100644 --- a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxyTest.java +++ b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/streams/InputStreamProxyTest.java @@ -38,6 +38,28 @@ public class InputStreamProxyTest { streamProvider = new StreamProviderImpl(); } + + + @Test + public void testUnsignedBytes() throws IOException { + int length = 1024; + ByteArrayOutputStream out = new ByteArrayOutputStream(length); + for(int i=0;i<length;i++) + { + out.write((byte)i); + } + byte[] data = out.toByteArray(); + byte[] result = new byte[data.length]; + int id = streamProvider.registerStream(new ByteArrayInputStream(data)); + + @SuppressWarnings("resource") + InputStreamProxy fixture = new InputStreamProxy(id, "", 1); + fixture.setStreamProvider(streamProvider); + assertEquals(length, fixture.read(result)); + assertArrayEquals(data, result); + assertEquals(-1, fixture.read()); + } + @Test public void testReadFully() throws IOException { int charSize = 10;