Skip to content

Commit feb088a

Browse files
authored
Merge pull request #349 from maxmind/greg/fix-4-gb-search-tree-lookups
Do not cause integer overflow during lookups on databases with search trees over 4 GB
2 parents f33d022 + f6a3ccf commit feb088a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
of binaries (e.g., `mmdblookup`) with the `MAXMINDDB_BUILD_BINARIES`
55
option and the install target generation with the `MAXMINDDB_INSTALL`
66
option. Pull request by Seena Fallah. GitHub #342.
7+
* The reader can now lookup records on a database with a search tree
8+
that is greater than 4 gigabytes without sometimes returning erroneous
9+
results due to an integer overflow.
710

811
## 1.9.1 - 2024-01-09
912

src/maxminddb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ static int find_address_in_search_tree(const MMDB_s *const mmdb,
947947
return MMDB_UNKNOWN_DATABASE_FORMAT_ERROR;
948948
}
949949

950-
uint32_t value = 0;
950+
uint64_t value = 0;
951951
uint16_t current_bit = 0;
952952
if (mmdb->metadata.ip_version == 6 && address_family == AF_INET) {
953953
value = mmdb->ipv4_start_node.node_value;
@@ -961,6 +961,7 @@ static int find_address_in_search_tree(const MMDB_s *const mmdb,
961961
uint8_t bit =
962962
1U & (address[current_bit >> 3] >> (7 - (current_bit % 8)));
963963

964+
// Note that value*record_info.record_length can be larger than 2**32
964965
record_pointer = &search_tree[value * record_info.record_length];
965966
if (record_pointer + record_info.record_length > mmdb->data_section) {
966967
return MMDB_CORRUPT_SEARCH_TREE_ERROR;

0 commit comments

Comments
 (0)