mirror of https://github.com/apache/activemq.git
[AMQ-6771] fix off by one on input stream read long check, with test
This commit is contained in:
parent
8c218ee05d
commit
3cd5529f50
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue