bugfix: packed input reading was broken for runs longer than 128 words.

This commit is contained in:
David Renshaw 2015-09-19 16:11:16 -04:00
parent 252acd2b32
commit 98500483c9
2 changed files with 10 additions and 6 deletions

View file

@ -76,7 +76,7 @@ public final class PackedInputStream implements ReadableByteChannel {
}
}
if (inBuf.remaining() ==0 && (tag == 0 || tag == (byte)0xff)) {
if (inBuf.remaining() == 0 && (tag == 0 || tag == (byte)0xff)) {
inBuf = this.inner.getReadBuffer();
}
} else {
@ -94,7 +94,7 @@ public final class PackedInputStream implements ReadableByteChannel {
throw new Error("Should always have non-empty buffer here.");
}
int runLength = inBuf.get() * 8;
int runLength = (0xff & (int)inBuf.get()) * 8;
if (runLength > outEnd - outPtr) {
throw new Error("Packed input did not end cleanly on a segment boundary");
@ -105,8 +105,7 @@ public final class PackedInputStream implements ReadableByteChannel {
}
} else if (tag == (byte)0xff) {
int runLength = inBuf.get() * 8;
int runLength = (0xff & (int)inBuf.get()) * 8;
if (inBuf.remaining() >= runLength) {
//# Fast path.

View file

@ -51,8 +51,6 @@ class SerializePackedSuite extends FunSuite {
(bytes) should equal (unpacked)
}
}
test("SimplePacking") {
@ -80,5 +78,12 @@ class SerializePackedSuite extends FunSuite {
expectPacksTo(Array(0,0,0,0,2,0,0,0, 0,0,0,0,0,0,1,0, 0,0,0,0,0,0,0,0),
Array(0x10,2, 0x40,1, 0,0))
expectPacksTo(Array.tabulate[Byte](8 * 200)((n) => 0),
Array(0, 199.toByte))
expectPacksTo(Array.tabulate[Byte](8 * 200)((n) => 1),
Array.concat(Array(0xff.toByte, 1,1,1,1,1,1,1,1, 199.toByte),
Array.tabulate[Byte](8 * 199)((n) => 1)))
}
}