[AMQ-6771] fix off by one on input stream read long check, with test

This commit is contained in:
gtully 2017-07-18 12:28:12 +01:00
parent 8c218ee05d
commit 3cd5529f50
2 changed files with 12 additions and 1 deletions

View File

@ -226,7 +226,7 @@ public final class DataByteArrayInputStream extends InputStream implements DataI
} }
public long readLong() throws IOException { public long readLong() throws IOException {
if (pos + 8 >= buf.length ) { if (pos + 8 > buf.length ) {
throw new EOFException(); throw new EOFException();
} }
long rc = ((long)buf[pos++] << 56) + ((long)(buf[pos++] & 255) << 48) + ((long)(buf[pos++] & 255) << 40) + ((long)(buf[pos++] & 255) << 32); long rc = ((long)buf[pos++] << 56) + ((long)(buf[pos++] & 255) << 48) + ((long)(buf[pos++] & 255) << 40) + ((long)(buf[pos++] & 255) << 32);

View File

@ -76,4 +76,15 @@ public class DataByteArrayInputStreamTest {
String readBack = in.readUTF(); String readBack = in.readUTF();
assertEquals(value, readBack); assertEquals(value, readBack);
} }
@Test
public void testReadLong() throws Exception {
DataByteArrayOutputStream out = new DataByteArrayOutputStream(8);
out.writeLong(Long.MAX_VALUE);
out.close();
DataByteArrayInputStream in = new DataByteArrayInputStream(out.getData());
long readBack = in.readLong();
assertEquals(Long.MAX_VALUE, readBack);
}
} }