Skip to content

Commit ae20d19

Browse files
committed
Fix a bug in the bounds checking
when resolving a data pointer.
1 parent 4ea6929 commit ae20d19

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log #
22

3+
## 0.26.0
4+
5+
* Fixed an internal bounds checking error when resolving data pointers.
6+
The previous logic could cause a panic on a corrupt database.
7+
8+
39
## 0.25.0 - 2025-02-16
410

511
* Serde will now skip serialization of the GeoIP2 struct fields

src/maxminddb/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ impl<'de, S: AsRef<[u8]>> Reader<S> {
492492
fn resolve_data_pointer(&self, pointer: usize) -> Result<usize, MaxMindDBError> {
493493
let resolved = pointer - (self.metadata.node_count as usize) - 16;
494494

495-
if resolved > self.buf.as_ref().len() {
496-
return Err(MaxMindDBError::InvalidDatabaseError(
497-
"the MaxMind DB file's search tree \
498-
is corrupt"
495+
// Check bounds using pointer_base which marks the start of the data section
496+
if resolved >= (self.buf.as_ref().len() - self.pointer_base) {
497+
return Err(MaxMindDBError::InvalidDatabaseError(
498+
"the MaxMind DB file's data pointer resolves to an invalid location"
499499
.to_owned(),
500500
));
501501
}

0 commit comments

Comments
 (0)