sunlishuo25 opened a new pull request, #23681: URL: https://github.com/apache/kafka/pull/23681
`ByteBufferInputStream.read(byte[], int, int)` can accept an invalid destination range when it shortens the requested length to the remaining input. With one input byte, reading two bytes into a one-byte array returns 1 instead of throwing `IndexOutOfBoundsException`. At EOF or for zero-length reads, it can also accept invalid bounds or a null array. Validate the original array range before early returns and length truncation. The regression tests cover invalid bounds, null arrays, and valid zero-length reads, including an exhausted input buffer. Validation: compiled the actual production classes and the full `ByteBufferInputStreamTest` class with `javac --release 11` on JDK 21, then ran JUnit Jupiter 5.14.4. The unchanged production code fails 5 of 9 tests; the fix passes all 9. File-scoped checks using Kafka's Checkstyle 12.3.1 configuration and Spotless 4.10.0 import-order step also pass. The official Gradle tasks, full clients suite, and CI JDKs 17/25 have not been run locally. This is my original contribution, prepared with AI assistance from OpenAI Codex (GPT-6). I have the right to submit it and license it under the project's Apache-2.0 license. Generated-by: OpenAI Codex (GPT-6) -- 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]
