leerho opened a new pull request, #810:
URL: https://github.com/apache/datasketches-java/pull/810

   Java counterparts of checks added in ds-cpp #587. Independent of #808 and 
#809 (no conflicts).
   
   ## REQ
   
   **The section count could overflow.** The number of sections in a compactor 
starts at 3 and doubles when the compactor's state reaches 2^(numSections − 1). 
Going from 48 to 96 needs a state of 2^47, which only a crafted image provides. 
In Java the section count is a `byte`, so doubling 96 wraps it to −64, and the 
compactor is then unusable and can't be serialized and read back.
   - `ensureEnoughSections()` now stops at `MAX_NUM_SECTIONS` = 48. C++ #587 
also stops at 48. Real sketches never reach 96, so normal results don't change.
   - `heapify` rejects a compactor with more than 48 sections. Before, up to 
127 were accepted as long as sectionSize × numSections ≤ k².
   
   **N wasn't checked.** In an estimation-mode image, N is now checked against 
the total weight of the retained items, where each item at level h weighs 2^h. 
Compaction keeps that total equal to N, so any difference means the image is 
corrupt. The check guards against overflow when it adds up the weights.
   
   ## KLL
   
   For full compact and updatable images, `KllMemorySegmentValidate` now 
rejects an n that is negative, or less than the number of retained items, since 
each retained item weighs at least one. This covers both heapify and wrap, for 
all four types. Empty and single-item images don't store n.
   
   ## Testing
   
   - `ReqCorruptImageTest`:
     - `checkTooManySections`: 49 sections are rejected and 48 are accepted.
     - `checkSectionDoublingStopsAtMax`: a compactor with state 2^50 and 48 
sections stays at 48 after a merge.
     - `checkNNotEqualToWeight`: N + 1, a negative N and `Long.MAX_VALUE` are 
all rejected, without large allocations.
   - `KllCorruptNTest`: for doubles, floats, longs and items, with heapify and 
wrap, and both compact and updatable images:
     - an n equal to the retained count is accepted;
     - retained − 1, −1 and `Long.MIN_VALUE` are rejected.
     All three tests fail on main.
   - The full suite passes (2,454 tests), including the CL files. `javac 
-Xlint:all -Xdoclint:all,-missing` reports nothing in the changed files.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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