Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

ArrayIndexOutOfBoundsException when using GEOIP_INDEX_CACHE #15

Closed
iconara opened this issue Feb 13, 2014 · 10 comments
Closed

ArrayIndexOutOfBoundsException when using GEOIP_INDEX_CACHE #15

iconara opened this issue Feb 13, 2014 · 10 comments

Comments

@iconara
Copy link

iconara commented Feb 13, 2014

When using the GEOIP_INDEX_CACHE I get an ArrayIndexOutOfBoundsException for two IPs (out of the whole IPv4 range, I tested them all).

This is the code:

LookupService lookup = new LookupService("GeoIP-133_20130305/GeoIPCity.dat", LookupService.GEOIP_INDEX_CACHE);
lookup.getLocation("223.255.245.158");

this is the error:

java.lang.ArrayIndexOutOfBoundsException: 51448944
    at com.maxmind.geoip.LookupService.seekCountry(LookupService.java:1224)
    at com.maxmind.geoip.LookupService.getLocation(LookupService.java:939)
    at com.maxmind.geoip.LookupService.getLocation(LookupService.java:667)
    at com.maxmind.geoip.LookupService.getLocation(LookupService.java:680)
    at Test.main(Test.java:7)

It happens for the IPs 223.255.245.158 and 223.255.245.159, but no other (I didn't scan the whole IPv4 space just for fun -- one of our production systems crashed and we wanted to make sure this wasn't a common issue).

As you can see I'm using a pretty old database here, and I aknowledge that this could be a problem that has gone away with newer databases. However, it doesn't happen when not using GEOIP_INDEX_CACHE, and even if it has gone away, there is still some bounds checking that is not happening.

I have verified this with 1.2.10 and 1.2.11.

@oschwald
Copy link
Member

Thanks for the report. Although this hasn't been reported previously, it sounds like this may be a bug in the API. We will look into it.

@borisz
Copy link
Contributor

borisz commented Mar 5, 2014

I'm unable to reproduce the error.
Please make sure we use the same database file.

bz$ ll /tmp/GeoIPCity-20130305.dat 
-rw-rw-r--  1 bz  wheel  56406935 Mar  5 05:08 /tmp/GeoIPCity-20130305.dat

bz$ md5sum /tmp/GeoIPCity-20130305.dat 
a343d7e750f36ab7828c9923f5388b3d  /tmp/GeoIPCity-20130305.dat

bz$ geoiplookup -v -f /tmp/GeoIPCity-20130305.dat 1
GeoIP City Edition, Rev 1: GEO-133 20130305 Build 1 Copyright (c) 2012 MaxMind Inc All Rights Reserved

PS: which API do you use? I could not find any LookupService.java file with 1224 lines.

@iconara
Copy link
Author

iconara commented Mar 5, 2014

Here is the line where the exception is thrown: https://github.com/maxmind/geoip-api-java/blob/v1.2.11/src/main/java/com/maxmind/geoip/LookupService.java#L1224

Notice the version tag. 1.2.11 is the latest version available for download.

@iconara
Copy link
Author

iconara commented Mar 5, 2014

My database file has the same MD5 sum, so I assume that you built the library from master and tested with that.

The only change to that file in the last six months is the pull request that you merged two weeks ago, maybe that fixed it? In that case a new release is all that's needed to fix this issue.

@iconara
Copy link
Author

iconara commented Mar 5, 2014

Unfortunately it's almost impossible for me to see how that PR fixed this issue since the whole LookupService class was reindented and shows up as changed.

@oschwald
Copy link
Member

oschwald commented Mar 5, 2014

You can see the differences without the whitespace changes by doing a git diff -w v1.2.11..master. I am not seeing any changes in master that are related. Most of the code changes are removing code for a non-functional service.

@oschwald
Copy link
Member

oschwald commented Mar 5, 2014

What JDK and platform do you use?

@iconara
Copy link
Author

iconara commented Mar 5, 2014

I've confirmed the bug in:

$ java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

and

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.14) (amazon-65.1.11.14.57.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

@borisz
Copy link
Contributor

borisz commented Mar 5, 2014

I'm able to reproduce the error.

@oschwald
Copy link
Member

oschwald commented Mar 5, 2014

We believe this has been fixed in master.

@oschwald oschwald closed this as completed Mar 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants