Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ private CompressedVSizeColumnarIntsSupplier(
sizePer == (1 << Integer.numberOfTrailingZeros(sizePer)),
"Number of entries per chunk must be a power of 2"
);
Preconditions.checkArgument(
numBytes >= 1 && numBytes <= Integer.BYTES,
"Invalid numBytes[%s] in CompressedVSizeColumnarIntsSupplier. Must be in range[1, %s]",
numBytes,
Integer.BYTES
);

this.totalSize = totalSize;
this.sizePer = sizePer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ public void testSanityWithSerde() throws Exception
assertIndexMatchesVals();
}

@Test
public void testInvalidNumBytesRejected() throws Exception
{
vals = new int[]{0, 1, 2, 3};
CloseableUtils.closeAndWrapExceptions(columnarInts);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
final CompressedVSizeColumnarIntsSupplier serialized = CompressedVSizeColumnarIntsSupplier.fromList(
IntArrayList.wrap(vals), Ints.max(vals), 4, byteOrder, compressionStrategy, closer
);
serialized.writeTo(Channels.newChannel(baos), null);
final byte[] bytes = baos.toByteArray();

for (byte invalidNumBytes : new byte[]{0, 5, 100, -1}) {
final byte[] corrupted = bytes.clone();
corrupted[1] = invalidNumBytes;
final IllegalArgumentException e = Assertions.assertThrows(
IllegalArgumentException.class,
() -> CompressedVSizeColumnarIntsSupplier.fromByteBuffer(ByteBuffer.wrap(corrupted), byteOrder, null)
);
Assertions.assertTrue(e.getMessage().contains("numBytes"), e.getMessage());
}
}


// This test attempts to cause a race condition with the DirectByteBuffers, it's non-deterministic in causing it,
// which sucks but I can't think of a way to deterministically cause it...
Expand Down
Loading