node-maxmind icon indicating copy to clipboard operation
node-maxmind copied to clipboard

watchForUpdates doesn't validate file

Open armoreal opened this issue 3 years ago • 0 comments

Seems watchForUpdates doesn't check if the file is valid (for example if upload was broken). And crash with

mmdb-lib/lib/decoder.js:106
        throw new Error('Unknown type ' + type + ' at offset ' + offset);
              ^

Error: Unknown type 87 at offset 1
    at Decoder.decodeByType (/home/nodejs/node_modules/mmdb-lib/lib/decoder.js:106:15)
    at Decoder.decode (/home/nodejs/node_modules/mmdb-lib/lib/decoder.js:58:21)
    at parseMetadata (/home/nodejs/node_modules/mmdb-lib/lib/metadata.js:14:30)
    at Reader.load (/home/nodejs/node_modules/mmdb-lib/lib/index.js:32:54)
    at StatWatcher.<anonymous> (/home/nodejs/node_modules/maxmind/lib/index.js:56:20)

I suggest to check if mmdb file is valid and only then replace db in memory with new file.

armoreal avatar May 08 '22 11:05 armoreal