Use checked arithmetic in dense ZeroTrie#7443
Use checked arithmetic in dense ZeroTrie#7443robertbastian merged 4 commits intounicode-org:mainfrom
Conversation
| let trie = ZeroAsciiDenseSparse2dTrieOwned::try_from_btree_map_str(&data, b'/').unwrap(); | ||
| let trie = trie.as_borrowed(); | ||
|
|
||
| // With empty dense matrix, all lookups should still work via sparse path |
There was a problem hiding this comment.
Suggestion: assert the Debug output of the trie, which encodes the values that went into sparse and the values that went into dense.
|
Hey @sffc i can see there's 2 fail in the check (semver fails after 8m), looking at the logs, it is due to a pre-existing issue, they're in icu_calendar and icu_locale_core. |
|
@sffc made the required changes, PTAL |
b786821 to
0f7cf5e
Compare
sffc
left a comment
There was a problem hiding this comment.
I would appreciate another review from @unicode-org/icu4x-owners since I think this adds branches to a hot path function which maybe doesn't pull its weight. We should avoid building tries that would cause this type of overflow.
Manishearth
left a comment
There was a problem hiding this comment.
I think the brances are fine, we already have another branch below. These should all just branch predict together.
Maintainer feedback Co-authored-by: Shane F. Carr <[email protected]>
utils/zerotrie/src/dense.rs
Outdated
| return None; | ||
| } | ||
| Some(usize::from(offset) + row_value_offset) | ||
| usize::from(offset).checked_add(row_value_offset) |
There was a problem hiding this comment.
Thought: Maybe this one should debug assert, too
|
@sffc please review the PRs, made the changes |
Closes #7442
Adds overflow protection to
ZeroAsciiDenseSparse2dTrieBorrowed::get()using checked arithmetic operations.Changes
File: utils/zerotrie/src/dense.rs
checked_mul()andchecked_add()checked_add()which perevents overflow when adding offset to row_value_offset