mjsax commented on code in PR #23158:
URL: https://github.com/apache/kafka/pull/23158#discussion_r3808703465


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorRecordContext.java:
##########
@@ -195,6 +196,9 @@ public static ProcessorRecordContext deserialize(final 
ByteBuffer buffer) {
         if (headerCount == -1) { // keep for backward compatibility
             headers = new RecordHeaders();
         } else {
+            if (headerCount < 0 || headerCount > buffer.remaining() / 4) {

Review Comment:
   Why `/ 4` ? We should not user `4` anyway... It seems the natural bound 
would be `/ (2 * Integer.BYTES)`, because `getNullableSizePrefixedArray()` 
reads the size of the key and value as one integer each?



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/ProcessorRecordContext.java:
##########
@@ -195,6 +196,9 @@ public static ProcessorRecordContext deserialize(final 
ByteBuffer buffer) {
         if (headerCount == -1) { // keep for backward compatibility
             headers = new RecordHeaders();
         } else {
+            if (headerCount < 0 || headerCount > buffer.remaining() / 4) {
+                throw new BufferUnderflowException();

Review Comment:
   ```suggestion
                   throw new SerializationException();
   ```



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/ProcessorRecordContextTest.java:
##########
@@ -110,4 +113,52 @@ public void shouldEstimateNullValueInHeaderAsZero() {
 
         assertEquals(MIN_SIZE + 10L, context.residentMemorySizeEstimate());
     }
+
+    @Test
+    public void shouldRejectHeaderCountLargerThanRemainingBuffer() {
+        final Headers headers = new RecordHeaders();
+        headers.add("header-key", "header-value".getBytes());

Review Comment:
   ```suggestion
           headers.add("header-key", "header-value".getBytes(UTF_8));
   ```
   Similar below.



-- 
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]

Reply via email to