dfengliu opened a new pull request, #20243:
URL: https://github.com/apache/druid/pull/20243

   ### Description
   
   `CompressedBlockReader.fromByteBuffer()` only checks the upper bound of the 
`blockSize` header field. The lower bound of `blockSize` and the `numBlocks` 
field are trusted verbatim, and the offset-table arithmetic (`numBlocks * 
Integer.BYTES`) is done without checking it against the remaining buffer. A 
corrupted or tampered header therefore surfaces as raw JVM exceptions on first 
use instead of a descriptive error:
   
   - `numBlocks = 0` -> `IndexOutOfBoundsException` (`offsetView.get(-1)`)
   - `numBlocks = -5` -> `IllegalArgumentException: newLimit < 0 (-10 < 0)`
   - `blockSize = 0` -> `IllegalArgumentException: newPosition > limit (30 > 
14)`
   - oversized `numBlocks` makes the reader slice the offsets table beyond the 
buffer
   
   #### Fixed the bug ...
   
   Validate the header before any offset math: `blockSize > 0`, `numBlocks > 
0`, and `numBlocks * Integer.BYTES <= buffer.remaining()`, raising a 
descriptive `IllegalArgumentException` (`"Block size[%s] must be positive"` / 
`"Number of blocks[%s] must be positive"` / `"Number of blocks[%s] exceeds the 
available buffer"`).
   
   Added `CompressedBlockReaderTest` covering rejection of the 
zero/negative/beyond-buffer cases plus a valid-header acceptance case. I 
verified the tests fail without the fix (they reproduce the raw 
`IndexOutOfBoundsException` / `IllegalArgumentException` above) and pass with 
it; `git diff --check` is clean.
   
   #### Release note
   
   - Reject malformed `CompressedBlockReader` headers (`blockSize`/`numBlocks` 
of zero, negative, or exceeding the buffer) with a descriptive error instead of 
failing later with an unrelated JVM exception.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `CompressedBlockReader`
    * `CompressedBlockReaderTest`
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [ ] added documentation for new or modified features or behaviors.
   - [x] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to