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

   `FrequentLongsSketch.getInstance(String)` builds the hash map from the 
length and numActive tokens in the string without checking either against the 
map. The probe loops in `ReversePurgeLongHashMap` (`adjustOrPutValue`, 
`hashProbe`) only stop at an empty slot, and the only guard is an `assert`, so 
once every slot is taken a probe for a new key spins forever. 
`getInstance("1,10,3,0,3,0,3,2,1,1,2,1,3,1")` never returns, and an empty image 
that claims a map length of 2 (`"1,10,3,5,0,0,0,2"`) deserializes fine but 
hangs on the third distinct `update()`, because `curMapCap` is computed from 
the 8-slot minimum while the map only has 2 slots. With assertions off this is 
an unbounded CPU loop from a ~30 byte input in any service that deserializes 
sketch strings it receives.
   
   Reject a map length below `1 << LG_MIN_MAP_SIZE` and a numActive outside 
`[0, capacity]` in `getInstance(String)`, next to the existing "Possible 
Corruption" checks. `serializeToString()` never produces either, so valid 
images are unaffected; the `MemorySegment` path already goes through `update()` 
and resizes/purges, so it does not need the same check. Added two tests to 
`LongsSketchTest` (with a timeout so a regression fails instead of hanging the 
suite); `mvn clean verify` passes.
   


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