dfengliu opened a new pull request, #20447:
URL: https://github.com/apache/druid/pull/20447
### Description
`GenericIndexed` V1 trusts the serialized element count and the value offset
table verbatim. A malformed header therefore fails with unrelated raw JVM
exceptions on access, or silently misreads header bytes as values:
- negative count accepted -> `Index>=size` type failures on every access
- overflowing count (`0x40000001`) accepted (valuesOffset arithmetic wraps)
-> `IllegalArgumentException` / `IndexOutOfBoundsException`
- offset beyond the value region -> `BufferUnderflowException`
- offset before the value region -> `NegativeArraySizeException` (`new
byte[-9]` in `StringUtils.fromUtf8`) and, for other indices, a silent garbage
string built from header/marker bytes
All of these are contained by JVM bounds checks, so this is an
integrity/robustness issue for corrupted or tampered segment data, in the same
class as the recent `CompressedBlockReader` / `FixedIndexed` header validation
fixes.
#### Fixed the bug ...
- `GenericIndexed.V1` constructor now rejects a negative element count
(`"size[%s] must be non-negative"`) and a values offset that overflows or
exceeds the buffer (`"size[%s] exceeds the available buffer"`) — computed in
`long` to avoid the same wrap.
- `copyBufferAndGet` (and the single-threaded `bufferedIndexedGetByteBuffer`
path) now validates that the value range is inside the buffer before reading
(`"value offsets out of bounds: startOffset[%s], endOffset[%s], limit[%s]"`),
turning the raw exceptions and silent misreads into descriptive `IAE`s.
Legitimate empty/null values still work (`NULL_VALUE_SIZE_MARKER` check
preserved).
Added `GenericIndexedMalformedHeaderTest` covering negative/overflow counts,
out-of-range offsets (both directions), and a valid-header acceptance case. I
verified the new tests fail without the fix (reproducing
`NegativeArraySizeException`, `BufferUnderflowException`, and silent acceptance
of bad counts) and pass with it; `mvn validate` (checkstyle) and `mvn
-DstrictCompile test-compile` (Error Prone) pass locally, and the existing
`GenericIndexedTest` still passes.
#### Release note
- Reject malformed `GenericIndexed` V1 headers (negative/overflowing element
count, or value offsets outside the buffer) with a descriptive error instead of
raw JVM exceptions or silent misreads.
<hr>
##### Key changed/added classes in this PR
* `GenericIndexed`
* `GenericIndexedMalformedHeaderTest`
<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]