GeoIP_next_record corrupt data
Brought to you by:
tjmather
I've been using this kind of code to do statistics on GeoIP database (like calculating the "centres" of countries based on IPs):
GeoIP *geoip = GeoIP_open("GeoLiteCity.dat", GEOIP_STANDARD);
int iter = GeoIP_init_record_iter(geoip);
GeoIPRecord *r;
while(!GeoIP_next_record(geoip, &r, &iter) && r) {
// use r
GeoIPRecord_delete(r);
}
This code stopped working some time ago (I don't have the first GeoLiteCity.dat, that caused the problem) - GeoIP_next_record is now returning garbage on all GeoLiteCity.dat updates. I have attached a patch file, which seems to fix the problem for me (note: I figured out the binary offset by reading memory dumps, I haven't tested the code on any other .dat files).
record_buf offset patch
Thanks for finding this!
However, the problem is with the database layout and not the API. Should be fixed with the next GeoLite update. The patch is not needed.
Have a nice day!