Skip to content

gridRing: validate k before wiping the output array - #1235

Merged
isaacbrodsky merged 1 commit into
uber:masterfrom
lenamonj:gridring-negative-k
Oct 15, 2026
Merged

isaacbrodsky merged 1 commit into
uber:masterfrom
lenamonj:gridring-negative-k

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

gridRing wiped the caller's output array with memset(out, 0, 6 * k * sizeof(H3Index)) before any domain check ran, so a negative k became a size_t of about 1.8e19 and the write ran off the end of the buffer. AddressSanitizer on gridRing(origin, -1, out): negative-size-param: (size=-48). Callers saw E_DOMAIN only if the process survived the write.

The width now comes from maxGridRingSize, which rejects a negative k with E_DOMAIN before the wipe and computes the size in int64_t. Every k the function previously handled wipes the same width as before. The new test uses a heap buffer so the old write faults under ASan; it passes with the fix.

@CLAassistant

CLAassistant commented Sep 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coveralls

coveralls commented Sep 6, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 99.589% (+0.001%) from 99.588% — lenamonj:gridring-negative-k into uber:master

gridRing wiped the caller's array with a width of 6 * k before any domain
check ran, so a negative k became a size_t of about 1.8e19 and the memset
ran off the end of the buffer (AddressSanitizer: negative-size-param,
size=-48). The width now comes from maxGridRingSize, which rejects a
negative k with E_DOMAIN and computes the size in int64_t. Every k the
function previously handled wipes the same width as before.
@lenamonj

Copy link
Copy Markdown
Contributor Author

Anything else needed from me here? It has been approved and green since the 7th.

@isaacbrodsky
isaacbrodsky merged commit 28d83cd into uber:master Oct 15, 2026
47 checks passed
@lenamonj
lenamonj deleted the gridring-negative-k branch October 15, 2026 16:18
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.

5 participants