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

   ### Description
   
   `FixedIndexed.read()` trusts the `size` header field. A negative value 
surfaces as a raw JVM exception at load (`IllegalArgumentException: newPosition 
< 0`), and a crafted size whose `width * size` arithmetic wraps is **silently 
accepted**: e.g. `size = 0x40000002` with `width = 8` claims 1073741826 
elements while the buffer holds two longs, and `get(1073741824)` / 
`get(1073741825)` return the values of slot 0 / slot 1 because `valuesOffset + 
index * width` wraps — duplicated/shifted reads with no error.
   
   #### Fixed the bug ...
   
   Validate the header before any offset arithmetic: `size >= 0`, and `width * 
valuesCount <= buffer.remaining()` (computed in long to avoid the same wrap). 
Malformed headers now fail fast with a descriptive `IllegalArgumentException` 
(`"size[%s] must be non-negative"` / `"size[%s] with width[%s] exceeds the 
available buffer"`).
   
   Added `testNegativeSizeRejected` and `testSizeExceedingBufferRejected` to 
`FixedIndexedTest`. I verified both tests fail without the fix (reproducing the 
raw `newPosition < 0` / `newPosition > limit` exceptions) and pass with it; 
`mvn validate` (checkstyle) and `mvn -DstrictCompile test-compile` (Error 
Prone) also pass locally.
   
   #### Release note
   
   - Reject malformed `FixedIndexed` headers (negative size, or size exceeding 
the available buffer) with a descriptive error instead of failing later with an 
unrelated JVM exception or silently returning wrong values.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `FixedIndexed`
    * `FixedIndexedTest`
   
   <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