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

   ## Summary
   
   C++ accepted any serial version 3 compact image with the empty flag set, 
without checking the rest of the preamble. This PR applies the same check as 
Java `EmptyCompactSketch` (apache/datasketches-java#776), using the same mask 
and test values, so both languages accept and reject the same empty images.
   
   | | Value |
   |---|---|
   | Mask | `0x0000EFFFFFFFFFFF` |
   | Test (preamble longs 1) | `0x00000E0000030301` |
   | Legacy test (preamble longs 3) | `0x00000E0000030303` |
   
   ## Changes
   
   - New `compact_theta_sketch_parser::check_empty_v3`, used by `parse` (byte 
`deserialize` and `wrap`) and by stream `deserialize_v3`.
   - **Checked:** preamble longs, serial version, sketch type, bytes 3 and 4 
zero, read-only, empty and compact set, single-item and reserved bits 0, 6 and 
7 clear.
   - **Ordered flag ignored.** C++ before 3.3.0 and Java before 1.0.0 wrote 
empty images without it.
   - **Seed hash ignored in the 8-byte form.** Writers have used both 0 and the 
real seed hash.
   - **Legacy 24-byte form accepted.** Before 1.0.0, Java wrote empty sketches 
with p < 1 with preamble longs 3. These must have no entries and carry the 
expected seed hash. C++ never wrote this form.
   - **Stream position fixed.** For a legacy image, stream `deserialize_v3` now 
reads all 24 bytes instead of stopping after 8.
   
   Behavior change for users: empty images with non-zero bytes 3 and 4, 
read-only or compact missing, single-item or a reserved bit set, preamble longs 
2, or a malformed legacy form are now rejected. No C++ or Java release I tested 
writes any of these.
   
   ## Testing
   
   - Full suite passes (17/17).
   - Three new test cases mirror the Java ones: the mask and test rules, 5 
historical images accepted and 12 mangled images rejected, each through stream 
`deserialize`, byte `deserialize` and `wrap`.
   - Real images read as empty through all three entry points: 60 written by 
C++ 1.0.0-incubating, 2.0.0-incubating, 3.0.0, 3.2.0, 3.3.0 and current master, 
and 2 from Java sketches-core 0.9.0.
   
   🤖 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