Repository navigation
Fix h3Line returning uninitialized memory when the line crosses pentagon distortion - #116583
Conversation
h3Line builds its result in two passes. The sizing pass calls gridPathCellsSize and checks its H3Error, the result is then sized with PODArray::resize, which does not initialize elements, and the fill pass called gridPathCells and discarded the returned H3Error. The two passes do not validate the same thing. gridPathCellsSize validates only the two endpoints, while gridPathCells walks the intermediate cells and returns E_PENTAGON after a partial write when the line crosses pentagon distortion. The slots it never reached were returned to the client, so SELECT h3Line(toUInt64(585609238802333695), toUInt64(585624631965122559)) handed back a 3-element array whose third element was raw heap. The observed values were live heap addresses that varied between calls, and a plain SELECT with constant arguments is enough to reach it. Check the error, matching the sizing pass in the same function and the sibling h3HexRing, which has the identical two-pass shape and already checks it. h3Line and h3HexRing are the only two h3 functions that fill a resize()d PODArray this way, so the whole class now checks. The new arm in 04034_h3_functions_default_if_invalid pins that this also throws under functions_h3_default_if_invalid = 1: that setting substitutes a default for an invalid cell, and both endpoints here are valid. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal review and pre-PR validation gate (click to expand)Reviewed cold by me, then twice by an independent second model over the full diff:
One thing noticed and deliberately not pursued: the other
Session ids: impl |
|
Workflow [PR], commit [9b7bee6] Summary: ❌
AI ReviewSummaryThis PR fixes Missing context / blind spots
Final Verdict✅ No blocking issues found in the current diff. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
|
cc @nikitamikhaylov, here is the public fix you asked for. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 9b7bee6Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Praktika's own report for this head is Session id: cron:our-pr-ci-monitor:20260827-013000 |
9c421bd
Cherry pick #116583 to 26.7: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Cherry pick #116583 to 26.6: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Cherry pick #116583 to 26.3: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
… when the line crosses pentagon distortion
… when the line crosses pentagon distortion
… when the line crosses pentagon distortion
… when the line crosses pentagon distortion
Backport #116583 to 26.8: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Backport #116583 to 26.6: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Backport #116583 to 26.7: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Backport #116583 to 26.3: Fix `h3Line` returning uninitialized memory when the line crosses pentagon distortion
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
h3Linereturning uninitialized memory in the tail of the result array when a line between two valid H3 indices cannot be drawn because it crosses pentagon distortion. Such a call now throwsINCORRECT_DATA.Description
h3Linebuilds its result in two passes: a sizing pass that callsgridPathCellsSizeand checks itsH3Error, thenPODArray::resize, which does not initialize elements, then a fill pass that calledgridPathCellsand discarded itsH3Error.The two passes validate different things.
gridPathCellsSizevalidates only the two endpoints, whilegridPathCellswalks the intermediate cells and returnsE_PENTAGONafter a partial write when the line crosses pentagon distortion. The slots it never reached were returned to the client:On master this returns a 3-element array whose third element is not a valid H3 index. The observed values were pointer-shaped and changed between calls, so a constant query with plain
SELECTdiscloses server memory.This fix checks the error, matching the sizing pass above and the sibling
h3HexRing, which already checks it.h3Lineandh3HexRingare the only two h3 functions that fill aresize()dPODArraythis way, so the whole class now checks; the other h3 functions that discard anH3Errorfill value-initializing containers.gridPathCellsfails only by returning early from its fill loop, so it never fails after writing every slot. The calls that now throw are exactly those that previously returned a partly uninitialized array. That includesfunctions_h3_default_if_invalid = 1: it substitutes a default for an invalid cell, and both endpoints here are valid. A test arm pins it.Validation: the three new arms fail on master, pass with the fix, and survive 50 randomized-settings runs; the two untouched
h3Linetests pass on both; the same pair throws throughmaterialize,Nullable,LowCardinalityand batched shapes, and non-pentagon inputs stay byte-identical to master.Reported to me privately as a core-security issue, with @ nikitamikhaylov asking for a public fix. The carrier is public code, so the fix belongs here; there is no public issue to link.
Workflow [PR]
Sync PR [sync-upstream/pr/116583]
Version info
26.9.1.194(included in26.9and later)26.8.3.57,26.7.7.38,26.6.5.65,26.3.33.10