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

(cherry picked from commit 3cd5529f505907912476a054758612a2eb22a1e0)
This commit is contained in:
gtully 2017-07-18 12:28:12 +01:00 committed by Timothy Bish
parent ba5e814667
commit a023c7a3e4
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 {
if (pos + 8 >= buf.length ) {
if (pos + 8 > buf.length ) {
throw new EOFException();
}
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();
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);
}
}