You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid int overflow of the output index in gridDiskDistancesUnsafe - #1270
gridDiskDistancesUnsafe fills the output with an int idx, but callers size that array with maxGridDiskSize(k), which has been 64 bit since #686. For k >= 26755 the disk is larger than INT32_MAX cells, so for an origin whose walk doesn't touch a pentagon (e.g. 8f283082800b390, res 15) idx++ overflows at algos.c:733 under UBSan and the next store goes to out[INT32_MIN], about 16 GiB before a correctly sized buffer. gridDisk and gridDiskDistances hit this because they try the unsafe path first. The int counters in gridRingUnsafe and _gridRingInternal, which index arrays of 6 * k, are widened the same way.
I checked it with a reproducer that backs the 16 GiB output with one 256 MiB file mapped repeatedly. Before the change it faults in gridDiskDistancesUnsafe under ASan/UBSan, and after it the call returns E_SUCCESS. There is no regression test because the case needs more than 2^31 output slots, which is too much for CI. The existing test suite passes.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: f3cfe3a1-84da-46fe-b876-b6dff0d94046
📥 Commits
Reviewing files that changed from the base of the PR and between 28d83cd and e2c3dd5.
📒 Files selected for processing: 2
CHANGELOG.md
src/h3lib/lib/algos.c
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Walkthrough
Grid traversal output indexes in _gridRingInternal, gridDiskDistancesUnsafe, and gridRingUnsafe now use int64_t. The Unreleased changelog records the signed overflow fix for large disk sizes and the ring index updates.
Changes
Grid output indexes
Layer / File(s)
Summary
Use 64-bit output indexes src/h3lib/lib/algos.c, CHANGELOG.md
_gridRingInternal, gridDiskDistancesUnsafe, and gridRingUnsafe use int64_t for output indexes. The changelog records the fix for disk sizes where k >= 26755 and maxGridDiskSize(k) > INT32_MAX.
The change addresses large-disk index overflow. No actionable merge-blocking issue is established by the available evidence.
Pre-merge checks: 5
Check name
Status
Explanation
Description check
The description clearly explains the signed integer overflow in gridDiskDistancesUnsafe and the related counter widening in gridRingUnsafe and _gridRingInternal.
Title check
The title clearly and concisely identifies the main change: preventing integer overflow in gridDiskDistancesUnsafe.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
coverage: 99.758%. remained the same — madib06ops:griddisk-int64-idx into uber:master
This branch has not been deployed
No deployments
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
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.
gridDiskDistancesUnsafefills the output with anint idx, but callers size that array withmaxGridDiskSize(k), which has been 64 bit since #686. Fork >= 26755the disk is larger thanINT32_MAXcells, so for an origin whose walk doesn't touch a pentagon (e.g.8f283082800b390, res 15)idx++overflows atalgos.c:733under UBSan and the next store goes toout[INT32_MIN], about 16 GiB before a correctly sized buffer.gridDiskandgridDiskDistanceshit this because they try the unsafe path first. The int counters ingridRingUnsafeand_gridRingInternal, which index arrays of6 * k, are widened the same way.I checked it with a reproducer that backs the 16 GiB output with one 256 MiB file mapped repeatedly. Before the change it faults in
gridDiskDistancesUnsafeunder ASan/UBSan, and after it the call returnsE_SUCCESS. There is no regression test because the case needs more than 2^31 output slots, which is too much for CI. The existing test suite passes.