lucliu1108 commented on code in PR #23156:
URL: https://github.com/apache/kafka/pull/23156#discussion_r3809445626
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/ProcessorMetadataTest.java:
##########
@@ -161,4 +165,55 @@ public void shouldNotUseCommitFlagForHashcodeAndEquals() {
assertEquals(metadata1, metadata2);
assertEquals(metadata1.hashCode(), metadata2.hashCode());
}
+
+ @Test
+ public void shouldThrowWhenKeySizeExceedsRemainingBytes() {
+ final byte[] keyBytes = "key1".getBytes(StandardCharsets.UTF_8);
+ final int fakeKeySize = keyBytes.length + Long.BYTES + 1; // one past
what's actually left for this entry
+
+ final ByteBuffer buf = ByteBuffer.allocate(Integer.BYTES +
Integer.BYTES + keyBytes.length + Long.BYTES);
+ buf.putInt(1); // entrySize = 1, legitimate
+ buf.putInt(fakeKeySize); // keySize is too large
+ buf.put(keyBytes);
+ buf.putLong(1L);
+ final byte[] serialized = new byte[buf.position()];
+ buf.position(0);
+ buf.get(serialized);
+
+ assertThrows(BufferUnderflowException.class, () ->
ProcessorMetadata.deserialize(serialized));
+ }
+
+ @Test
+ public void shouldThrowWhenKeySizeIsNegative() {
+ final ByteBuffer buf = ByteBuffer.allocate(Integer.BYTES +
Integer.BYTES);
+ buf.putInt(1); // entrySize = 1, legitimate
+ buf.putInt(-1); // keySize is negative
+
+ assertThrows(BufferUnderflowException.class, () ->
ProcessorMetadata.deserialize(buf.array()));
Review Comment:
Fix: I padded the buffer to 16 bytes so the `entrySize` check passes first,
and the execution reaches the negative `keySize` check instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]