Skip to content

HLL: check coupons and HLL_4 aux entries when reading an image - #824

Closed
leerho wants to merge 1 commit into
mainfrom
hll-image-checks
Closed

leerho wants to merge 1 commit into
mainfrom
hll-image-checks

Conversation

@leerho

@leerho leerho commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

HllUtil.checkPreamble now checks more of an image when it comes from outside the sketch. heapify, wrap and writableWrap all go through it, so all three apply the checks.

  • List and set images: a list or set marked empty must have a coupon count of 0. Each coupon must have a value (the top 6 bits are not 0) and appear once. In an updatable set, each coupon must be in the slot where a lookup finds it.
  • HLL_4 images: each register that holds the aux token (15) must have exactly one aux entry, and that entry's value must not fit in the register (at least curMin + 15). There must be no other entries. In an updatable image, each entry must be where a lookup finds it.

Before this change these images were read without an error, but then:

  • estimates and unions disagreed, for example a duplicate coupon counted once by one path and twice by another;
  • or the next update or union threw SketchesStateException or IndexOutOfBoundsException.

The checks only read the image. They scan at most the coupon table, or the K/2 register bytes and the aux table. That is similar to the HLL_8 register scan added in #814.

Testing

  • 11 new tests in HllCorruptImageTest, one per case, covering compact and updatable images. Each checks heapify, wrap, HllUnion.heapify and, for updatable images, writableWrap. All 11 fail without the change.
  • New test of valid HLL_4 images with aux entries: heap and direct sketches, and lgK 4 to 10 across a million updates, as curMin rises.
  • Full suite passes: 2,480 tests.
  • The C++, Go, Rust and historical-C++ CL file checks pass. check_CL_binary_files has the same 4 failures as main.

🤖 Generated with Claude Code

- a list or set image marked empty must have a zero count
- each coupon must have a value and appear once; in an updatable set
  each coupon must be where a lookup finds it
- in an HLL_4 image each register that refers to the aux map must have
  one aux entry, with a value that does not fit in the register, and
  there must be no other entries; in an updatable image each entry must
  be where a lookup finds it

The checks run in checkPreamble, so every way of reading an image
applies them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leerho

leerho commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Combined into #827 with the other sketches' checks of the same kind; the commits are unchanged.

@leerho leerho closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant