Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in search_tree_size #336

Merged
merged 2 commits into from
Jan 9, 2024
Merged

Conversation

oschwald
Copy link
Member

@oschwald oschwald commented Jan 8, 2024

Also, add guards to follow-up calculations to error if they overflow.

Closes #335.

@oschwald oschwald force-pushed the greg/fix-search-tree-size-overflow branch 2 times, most recently from 4dc2c22 to 060ebf1 Compare January 8, 2024 23:10
Also, add guards to follow-up calculations to error if they overflow.

Closes #335.
@oschwald oschwald force-pushed the greg/fix-search-tree-size-overflow branch from 060ebf1 to 0602d2e Compare January 8, 2024 23:23
Copy link
Contributor

@horgh horgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to change anything, but a couple questions.

src/maxminddb.c Outdated

mmdb->data_section =
mmdb->file_content + search_tree_size + MMDB_DATA_SECTION_SEPARATOR;
if (search_tree_size + MMDB_DATA_SECTION_SEPARATOR >
(uint32_t)mmdb->file_size) {
if (search_tree_size + MMDB_DATA_SECTION_SEPARATOR > mmdb->file_size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to check if this would overflow too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how plausibly this is an issue, but I did add a check. The first part of the updated check is likely redundant as finding the metadata would have failed if that is not true, but I left it for clarity.

src/maxminddb.c Show resolved Hide resolved
@horgh horgh merged commit 4d3d0a8 into main Jan 9, 2024
29 checks passed
@horgh horgh deleted the greg/fix-search-tree-size-overflow branch January 9, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Python vs C extension difference with large db
2 participants