Skip to content

[7.0.X] Backport CVE-2026-122096 deserialization fixes (#777, #783, theta image validation) - #817

Open
imrahib wants to merge 3 commits into
apache:7.0.Xfrom
imrahib:7.0.X-cve-2026-122096
Open

imrahib wants to merge 3 commits into
apache:7.0.Xfrom
imrahib:7.0.X-cve-2026-122096

Conversation

@imrahib

@imrahib imrahib commented Nov 24, 2026

Copy link
Copy Markdown

Summary

This backports the 9.1.0 fixes for CVE-2026-122096 to the 7.0.X branch. 9.1.0 requires Java 25, so users on Java 17 cannot take the fix today. A 7.0.2 release from this branch would give them one.

Commits

Commit Upstream source What it fixes
Reject undersized map in LongsSketch.getInstance(String) and getInstance(Memory) #777 (eb131f9) Infinite loop from a crafted string; lgCurMapSize checks on the binary preamble
Validate string SerDe bounds before allocation #783 (a6eac94) Large allocations from declared item counts and lengths in ArrayOfStringsSerDe and ArrayOfUtf16StringsSerDe
Theta: validate sketch, union and intersection images 4dc80fe Large allocations in Sketch/CompactSketch heapify and wrap, update and union images (including the int overflow in the size check for lgArrLongs >= 28), compressed images and intersection images

The theta commit is not part of #777 or #783, but without it Sketch.heapify(Memory) in 7.0.1 still allocates gigabytes from a 12 to 32 byte image.

Differences from 9.1.0

  • 7.0.X names and APIs: LongsSketch instead of FrequentLongsSketch, Memory instead of MemorySegment, UpdateSketch.checkMemIntegrity() instead of checkSegIntegrity().
  • 7.x only: ForwardCompatibility (serial version 1 and 2 images) computed the required size as (curCount + preLongs) << 3 in int arithmetic, which overflows. It is now computed in long arithmetic, and a negative curCount is rejected. 9.x no longer reads these images.
  • Tests are ported to Memory and check for SketchesArgumentException without AllocationTracker, which 7.0.X does not have.

Not included

The other 9.1.0 hardening commits: CountMin (8256f17), Frequencies binary item counts (c95fb7c), Tuple (8c2e288), ArrayOfDoubles (55d9b77), HLL (f8f41cd), Bloom (e004666), ArrayOfNumbersSerDe (3930b5a), Quantiles items (4e02458), REQ (024dc74), VarOpt (5061899) and CPC (9cf8254). They can be added to this PR or a follow-up if the PMC wants full parity for a 7.0.2 release.

Testing

  • mvn test on Java 17: 2192 tests, 0 failures.
  • The new tests fail on unpatched 7.0.1: 6 of 7 theta tests get OutOfMemoryError instead of SketchesArgumentException, and the string SerDe tests fail without the bounds checks.

Request

If the PMC accepts this, please consider releasing 7.0.2 and updating the CVE-2026-122096 record to list 7.0.2 as fixed, so dependency scanners stop flagging it.

Your Name added 3 commits November 24, 2026 16:04
…nce(Memory)

Backport of apache#777 (merged as eb131f9 for 9.1.0) to 7.0.X.
Part of the fix for CVE-2026-122096.

getInstance(String) built the hash map from the length and numActive tokens without
checking either against the map, so a crafted string could make deserialization, or
a later update(), probe forever. Reject a map length below 1 << LG_MIN_MAP_SIZE or
above the max map length, and numActive outside [0, capacity]. Apply the same
lgCurMapSize checks to the binary preamble in getInstance(Memory).

In 7.0.X the class is LongsSketch (renamed FrequentLongsSketch in 9.0.0).
Backport of apache#783 (merged as a6eac94 for 9.1.0) to 7.0.X.
Part of the fix for CVE-2026-122096.

ArrayOfStringsSerDe and ArrayOfUtf16StringsSerDe allocated the result array from
numItems, and each item's byte array from its declared length, before checking either
against the Memory capacity. Check that the Memory can hold numItems length prefixes
before allocating the array, and check each item's length before allocating its bytes.

Tests ported from StringSerDeBoundsTest, using Memory instead of MemorySegment.
Backport of apache/datasketches-java 4dc80fe (9.1.0) to 7.0.X.
Part of the fix for CVE-2026-122096. This commit is not in apache#777 or apache#783, but
Sketch.heapify() and the other theta deserializers are affected without it.

- checkMemIntegrity(), used for updatable, alpha and union images (heapify and wrap):
  check lgNomLongs <= 26, 0 <= lgArrLongs <= lgNomLongs + 1 and 0 <= curCount <= table
  size, and compute the required size in long arithmetic. (8 << lgArrLongs) overflowed
  int for lgArrLongs >= 28, which let a 32-byte image pass the size check.
- Compact images (heapify and wrap): check that curCount is non-negative and that the
  image holds the hashes. Images in hash-table form must hold the whole table.
- Compressed images (serial version 4): check preLongs, entryBits and numEntriesBytes,
  and that the image holds numEntries * entryBits bits.
- Intersection images (heapify and wrap): check 0 <= lgArrLongs <= 27,
  -1 <= curCount <= table size, and that the image holds the table when curCount > 0.

7.x only: serial version 1 and 2 images (ForwardCompatibility) computed the required
size as (curCount + preLongs) << 3 in int arithmetic, which overflowed. Compute it in
long arithmetic and reject a negative curCount. 9.x no longer reads these images.

Tests ported from ThetaCorruptImageTest, using Memory instead of MemorySegment and
without AllocationTracker, plus a test for the serial version 1 and 2 overflow.

This branch has not been deployed

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