diff --git a/CHANGELOG.md b/CHANGELOG.md index 40d89d4..3b9d2b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ CHANGELOG * Improve the error handling when the user tries to open a directory with the pure PHP reader. * Improve the typehints on arrays in the PHPDocs. +* The C extension now checks that the database metadata lookup was + successful. 1.11.1 (2023-12-01) ------------------- diff --git a/ext/maxminddb.c b/ext/maxminddb.c index 20e2bbf..b4e078b 100644 --- a/ext/maxminddb.c +++ b/ext/maxminddb.c @@ -336,7 +336,15 @@ PHP_METHOD(MaxMind_Db_Reader, metadata) { object_init_ex(return_value, metadata_ce); MMDB_entry_data_list_s *entry_data_list; - MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list); + int status = + MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list); + if (status != MMDB_SUCCESS) { + zend_throw_exception_ex(maxminddb_exception_ce, + 0 TSRMLS_CC, + "Error while decoding metadata. %s", + MMDB_strerror(status)); + return; + } zval metadata_array; const MMDB_entry_data_list_s *rv =