Permalink
Browse files

Check data type returned by MaxMind\Db\Reader. Fixes #83

  • Loading branch information...
1 parent e9e40f7 commit 417876af1229744b8201150071cd75fd413ae3c7 @oschwald oschwald committed Jan 30, 2017
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/Database/Reader.php
@@ -5,6 +5,7 @@
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\ProviderInterface;
use MaxMind\Db\Reader as DbReader;
+use MaxMind\Db\Reader\InvalidDatabaseException;
/**
* Instances of this class provide a reader for the GeoIP2 database format.
@@ -223,6 +224,19 @@ private function getRecord($class, $type, $ipAddress)
"The address $ipAddress is not in the database."
);
}
+ if (!is_array($record)) {
+ // This can happen on corrupt databases. Generally,
+ // MaxMind\Db\Reader will throw a
+ // MaxMind\Db\Reader\InvalidDatabaseException, but occasionally
+ // the lookup may result in a record that looks valid but is not
+ // an array. This mostly happens when the user is ignoring all
+ // exceptions and the more frequent InvalidDatabaseException
+ // exceptions go unnoticed.
+ throw new InvalidDatabaseException(
+ "Expected an array when looking up $ipAddress but received: "
+ . gettype($record)
+ );
+ }
return $record;
}

0 comments on commit 417876a

Please sign in to comment.