Skip to content

Commit aef9d7a

Browse files
author
olicesx
committed
fix(geoip): parse .dat with prost and fix merged network range computation
Replace the hand-written wire parser in load_from_dat_file (geoip.rs and geoip_converter.rs) with Google's standard protobuf library (prost), aligned with dae's pkg/geodata. The hand-written parser assumed fixed field order, single-byte tags and no unknown fields; any .dat variant silently produced wrong networks. Fix host-mask computation in the CIDR merge path: !u32::MAX << n is 0, so merged ranges collapsed to their start address, turning adjacent or overlapping networks into wrong prefixes. Use u32::MAX.wrapping_shr(prefix) for the host mask and align the merged start address to the covering prefix's network boundary before constructing the network.
1 parent e1536ac commit aef9d7a

6 files changed

Lines changed: 250 additions & 392 deletions

File tree

Cargo.lock

Lines changed: 30 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ hyper-util = { version = "0.1", features = ["server", "tokio"] }
4848
http-body-util = "0.1"
4949
rustls-pemfile = "2"
5050
base64 = "0.22"
51+
prost = { version = "0.14.4", features = ["derive"] }
5152

5253
[dev-dependencies]
5354
criterion = "0.5"

0 commit comments

Comments
 (0)