Closed pbiering closed 7 years ago
The fix in #80 only fixed some breakage introduced in #74 where the offset calculation was unintentionally changed. Based on your description, it sounds like what you are seeing predates that issue. Do you happen to know if ay version correctly parses the version strings? The relevant code is here.
For "ipv6calc" compatibility tests I have here all older versions and it looks like that current binary dat files are incompatible at least since version 1.4.4:
LD_LIBRARY_PATH=~/tmp/GeoIP-1.4.4/libGeoIP/.libs/ ./test_geoip_no_version /var/local/share/GeoIP/*.dat
INFO : file=/var/local/share/GeoIP/GeoIPASNum.dat GeoIP_database_info=>GEO-117 20161002 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Reser<
INFO : file=/var/local/share/GeoIP/GeoIPASNumv6.dat GeoIP_database_info=>GEO-117 20160911 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Re<
Imho one has to check/track changes in the dat file generator by code review and/or testing older releases of the dat file to see when this bug was introduced.
It looks to me that the current code finds the start of the database info string successfully, but is prone to truncating the string. Without knowing what the legacy database format looks like, it's hard to debug this in my head but it seems a bit strange that the loop variable i is involved both in finding the start of the string and its length. Would it not work to keep the code that finds the start of the database info and then take everything from there to a NULL character as long as it doesn't overflow the malloc-ed buffer?
That might work. I am not sure why the code was designed that way. This is further complicated by the fact that there are several different variations of the legacy format, all without detailed specifications.
I've just been looking at this and I think the current code is correct. The problem is the databases, not the code. The database info structure is at the end of the file, and by dumping the file contents using od, it's clear that the current GeoLite legacy databases have truncated database info strings, matching the output from @pbiering's test program. So it's the database generator that needs looking at.
@pghmcfc, thanks for looking into it! We'll take a look at the generation code.
This should be fixed in the latest GeoLite legacy databases.
I am going to close this issue as both the database reader and generation should now be fixed. Thanks for reporting!
The new databases look good to me. Thanks!
See also: https://bugzilla.redhat.com/show_bug.cgi?id=1426853
Looks like https://github.com/maxmind/geoip-api-c/issues/79 is not really fixed and also it looks like output depends on database version:
Old DBs from 2013 using library 1.6.9 (OK)
Old DBs using library version 1.5.0 (OK)
New DBs from 2016+ using library version 1.6.9 (BUGGY)
New DBs from 2016+ using library version 1.5.0 (BUGGY)
Test code is: