Repository navigation
Conversation
- 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>
- lgMaxMapSize must not exceed 30, the largest a sketch can be constructed with - each item count must be positive, and together they must not exceed the stream weight Both binary readers and the String reader apply the checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reference formats store k as a double or a float. It was cast to short before it was checked, so a value out of range could wrap to a valid k: 65546 read as 10. k must now be in [10, 32767] before the cast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The interpolation in getRank multiplied a weight by a difference of values, and divided by the difference of two centroid means. For means of opposite signs near Double.MAX_VALUE either can be infinite, and the rank was Infinity or NaN. It now falls back to a fraction computed from the halves of the values. For other values the arithmetic is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…double A tail centroid can hold the extreme value and values of the opposite sign, so its mean and min (or max) can have opposite signs. Near Double.MAX_VALUE their difference is not finite, and the tail interpolation in getQuantile gave NaN. It now uses the convex combination in that case. For other values the arithmetic is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 2, 2026
Theta is in (0, 1], so as a long it is in [1, Long.MAX_VALUE]. A theta of 0 or a negative thetaLong was accepted, and the sketch then gave an estimate of Infinity or a negative number. The check applies to compact and compressed compact images, updatable sketches, unions (including the union's own theta) and intersections, for heapify and wrap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The offset is the total weight removed from each counter by purges, so it is in [0, stream weight]. A negative or larger offset was accepted and returned as the maximum error. The check applies to the binary readers of FrequentLongsSketch and FrequentItemsSketch, and to FrequentLongsSketch.getInstance(String). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FrequentLongsSketch.getInstance(String) parsed each token with Integer.parseInt or Long.parseLong, so a token that is not a number threw NumberFormatException. Each token is now parsed through a helper that throws SketchesArgumentException instead, as the other checks of the String form do. The javadoc now documents the exception. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When reading an image, KllMemorySegmentValidate now checks: - numLevels is at least 1, and the MemorySegment holds the stored part of the levels array before it is read; - the level boundaries start at 0 or more and never decrease; - in the updatable form, the top boundary equals the item capacity that k, m and numLevels give, as the sketch's growth scheme keeps it; - the MemorySegment is at least as large as the image. Before, the updatable form took the item capacity from the image, and reading it allocated that many items. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The javadoc of the method that reads an image into a new sketch, in KllFloatsSketch, KllDoublesSketch and KllLongsSketch, named only the compact form, but both forms are accepted. It now names both and documents the SketchesArgumentException for an invalid image. KllItemsSketch has only the compact form and is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
proost
approved these changes
Dec 3, 2026
proost
left a comment
Member
There was a problem hiding this comment.
Current changes looks correct to me. But can you adding more strict validation too?
|
|
||
| //The image must have at least one level, and must hold the stored part of the levels array. | ||
| private void checkLevelsFit(final int storedLevels) { | ||
| if (numLevels < 1) { throw new SketchesArgumentException(LEVELS_INVALID + "numLevels: " + numLevels); } |
Member
There was a problem hiding this comment.
how about gurading numLevels > 61 too?
| * @throws SketchesArgumentException if it is larger than a sketch can be constructed with | ||
| */ | ||
| static void checkLgMaxMapSize(final int lgMaxMapSize) { | ||
| if (lgMaxMapSize > LG_MAX_MAP_SIZE) { |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This combines #824, #825 and #826 into one PR, and adds checks of theta, of the frequencies maximum error offset, and of the KLL levels array. They are the same kind of change (checks when reading a sketch) at the same priority. The commits from #824, #825 and #826 are unchanged.
HLL (from #824)
HllUtil.checkPreamblenow 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.Before this change these images were read without an error. Then estimates and unions disagreed (a duplicate coupon counted once by one path and twice by another), or the next update or union threw
SketchesStateExceptionorIndexOutOfBoundsException. The checks only read the image, and scan at most the coupon table, or the K/2 register bytes and the aux table.Frequencies (from #825)
In the binary readers of
FrequentLongsSketchandFrequentItemsSketch, and inFrequentLongsSketch.getInstance(String):FrequentLongsSketch.getInstance(String)threwNumberFormatExceptionfor a token that is not a number. It now throwsSketchesArgumentException, like its other checks, and the javadoc documents it.KLL
KllMemorySegmentValidatenow checks, for the doubles, floats, longs and items sketches, when reading or wrapping an image:numLevelsis at least 1, and the MemorySegment holds the stored part of the levels array before it is read;Before, the updatable form took the item capacity from the image, and reading it allocated that many items. The javadoc of the doubles, floats and longs reader now also says that it accepts both the compact and the updatable form, and names the exception.
Theta
Theta must be greater than 0. As a long it is in [1, Long.MAX_VALUE], and a value of 0 or a negative value was accepted, giving an estimate of Infinity or a negative number. The check applies to compact and compressed compact images, updatable sketches, unions (both the union's theta and its sketch's theta) and intersections, for heapify and wrap.
t-digest (from #826)
shortbefore it was checked, so 65546 read as 10. k must now be in [10, 32767] before the cast.getRanknear the largest double. When centroid means have opposite signs nearDouble.MAX_VALUE, the interpolation could be infinite, and the rank was Infinity or NaN. It now falls back to a fraction computed from halves of the values.getQuantilereturned NaN. It now uses the convex combination in that case.In 2 and 3, the original arithmetic is kept whenever it is finite, so results for all other inputs are unchanged.
Testing
HllCorruptImageTest(heapify, wrap,HllUnion.heapify, and writableWrap for updatable images), plus a test of valid HLL_4 images with aux entries across lgK 4 to 10 and a million updates.FrequenciesImageCountsTestfor the binary Longs and Items forms and the Longs String form, including purged and merged sketches and the largest map size.checkOffsetcovers the offset in all three forms, andcheckNonNumericTokenscovers every token of the String form.KllCorruptLevelsTest, with 7 rejection tests for both forms and both read paths, each checked to allocate under 1 MB. Before writing the checks, 5,600 valid images (all types, sketches with and without a MemorySegment, merges with different k) were confirmed to satisfy them.checkThetaNotPositiveinThetaCorruptImageTestcovers every form and path above.checkValidThetascovers estimation mode and sampling with a small p, including an empty sampled sketch.compatK,ranksAndQuantilesNearDoubleLimitsandtailQuantilesNearDoubleLimits.check_CL_binary_fileshas the same 4 failures as main.🤖 Generated with Claude Code