PaddeK / node-maxmind-db

This is the pure Node API for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).
GNU Lesser General Public License v2.1
88 stars 25 forks source link

Error with 32bit record size #11

Closed coderholic closed 9 years ago

coderholic commented 9 years ago

If you try and read an mmdb with a 32bit record size you get the following error:

TypeError: Cannot call method 'readUInt32BE' of undefined
  at [object Object].readNode ( node_modules/maxmind-db-reader/lib/Reader.js:130:26)
  at [object Object].findAddressInTree ( node_modules/maxmind-db-reader/lib/Reader.js:93:23)
  at [object Object].getSync ( node_modules/maxmind-db-reader/lib/Reader.js:59:24)
  at [object Object].getGeoDataSync ( node_modules/maxmind-db-reader/index.js:34:24)

Looking at the code at https://github.com/PaddeK/node-maxmind-db/blob/master/lib/Reader.js#L130 it seems that bytes it never set for this code path

the-eater commented 9 years ago

Im sorry for reacting late, do you have an mmdb with 32bit record size for me to test? or can you confirm that changing bytes to buffer on line 130 resolves the issue? :)

oschwald commented 9 years ago

MaxMind provides a 32-bit test database. It should have 1.1.1.1-1.1.1.32 and :1:ffff:ffff-::2:0000:0059 in it.

the-eater commented 9 years ago

Oh sweet, thanks :) will look into it now.

the-eater commented 9 years ago

Is fixed now and published on npm :)