diff options
Diffstat (limited to 'vendor/maxmind-db/reader')
-rw-r--r-- | vendor/maxmind-db/reader/CHANGELOG.md | 15 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/README.md | 19 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/autoload.php | 14 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/composer.json | 4 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/ext/config.m4 | 80 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/ext/config.w32 | 10 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/ext/maxminddb.c | 591 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/ext/php_maxminddb.h | 2 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/package.xml | 12 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php | 218 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php | 134 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php | 9 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Metadata.php | 156 | ||||
-rw-r--r-- | vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Util.php | 11 |
14 files changed, 792 insertions, 483 deletions
diff --git a/vendor/maxmind-db/reader/CHANGELOG.md b/vendor/maxmind-db/reader/CHANGELOG.md index d413e4f..7c954ea 100644 --- a/vendor/maxmind-db/reader/CHANGELOG.md +++ b/vendor/maxmind-db/reader/CHANGELOG.md @@ -1,6 +1,21 @@ CHANGELOG
=========
+1.11.1 (2023-12-01)
+-------------------
+
+* Resolve warnings when compiling the C extension.
+* Fix various type issues detected by PHPStan level. Pull request by
+ LauraTaylorUK. GitHub #160.
+
+1.11.0 (2021-10-18)
+-------------------
+
+* Replace runtime define of a constant to facilitate opcache preloading.
+ Reported by vedadkajtaz. GitHub #134.
+* Resolve minor issue found by the Clang static analyzer in the C
+ extension.
+
1.10.1 (2021-04-14)
-------------------
diff --git a/vendor/maxmind-db/reader/README.md b/vendor/maxmind-db/reader/README.md index 5b3f21e..92280ba 100644 --- a/vendor/maxmind-db/reader/README.md +++ b/vendor/maxmind-db/reader/README.md @@ -112,9 +112,16 @@ you are using an autoloader, no changes to your code should be necessary. First install [libmaxminddb](https://github.com/maxmind/libmaxminddb) as
described in its [README.md
-file](https://github.com/maxmind/libmaxminddb/blob/master/README.md#installing-from-a-tarball).
-After successfully installing libmaxmindb, run the following commands from the
-top-level directory of this distribution:
+file](https://github.com/maxmind/libmaxminddb/blob/main/README.md#installing-from-a-tarball).
+After successfully installing libmaxmindb, you may install the extension
+from [pecl](https://pecl.php.net/package/maxminddb):
+
+```
+pecl install maxminddb
+```
+
+Alternatively, you may install it from the source. To do so, run the following
+commands from the top-level directory of this distribution:
```
cd ext
@@ -125,7 +132,7 @@ make test sudo make install
```
-You then must load your extension. The recommend method is to add the
+You then must load your extension. The recommended method is to add the
following to your `php.ini` file:
```
@@ -157,7 +164,7 @@ client API, please see [our support page](https://www.maxmind.com/en/support). ## Requirements ##
-This library requires PHP 5.6 or greater.
+This library requires PHP 7.2 or greater.
The GMP or BCMath extension may be required to read some databases
using the pure PHP API.
@@ -173,6 +180,6 @@ The MaxMind DB Reader PHP API uses [Semantic Versioning](https://semver.org/). ## Copyright and License ##
-This software is Copyright (c) 2014-2019 by MaxMind, Inc.
+This software is Copyright (c) 2014-2023 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0.
diff --git a/vendor/maxmind-db/reader/autoload.php b/vendor/maxmind-db/reader/autoload.php index c79126f..7dab1eb 100644 --- a/vendor/maxmind-db/reader/autoload.php +++ b/vendor/maxmind-db/reader/autoload.php @@ -1,5 +1,7 @@ <?php
+declare(strict_types=1);
+
/**
* PSR-4 autoloader implementation for the MaxMind\DB namespace.
* First we define the 'mmdb_autoload' function, and then we register
@@ -14,7 +16,7 @@ * @param string $class
* the name of the class to load
*/
-function mmdb_autoload($class)
+function mmdb_autoload($class): void
{
/*
* A project-specific mapping between the namespaces and where
@@ -26,16 +28,16 @@ function mmdb_autoload($class) $namespace_map = ['MaxMind\\Db\\' => __DIR__ . '/src/MaxMind/Db/'];
foreach ($namespace_map as $prefix => $dir) {
- /* First swap out the namespace prefix with a directory... */
+ // First swap out the namespace prefix with a directory...
$path = str_replace($prefix, $dir, $class);
- /* replace the namespace separator with a directory separator... */
+ // replace the namespace separator with a directory separator...
$path = str_replace('\\', '/', $path);
- /* and finally, add the PHP file extension to the result. */
- $path = $path . '.php';
+ // and finally, add the PHP file extension to the result.
+ $path .= '.php';
- /* $path should now contain the path to a PHP file defining $class */
+ // $path should now contain the path to a PHP file defining $class
if (file_exists($path)) {
include $path;
}
diff --git a/vendor/maxmind-db/reader/composer.json b/vendor/maxmind-db/reader/composer.json index d4debfb..e5b5b1f 100644 --- a/vendor/maxmind-db/reader/composer.json +++ b/vendor/maxmind-db/reader/composer.json @@ -21,10 +21,10 @@ "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups"
},
"conflict": {
- "ext-maxminddb": "<1.10.1,>=2.0.0"
+ "ext-maxminddb": "<1.11.1,>=2.0.0"
},
"require-dev": {
- "friendsofphp/php-cs-fixer": "*",
+ "friendsofphp/php-cs-fixer": "3.*",
"phpunit/phpunit": ">=8.0.0,<10.0.0",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpcov": ">=6.0.0",
diff --git a/vendor/maxmind-db/reader/ext/config.m4 b/vendor/maxmind-db/reader/ext/config.m4 index 675e00c..2e19947 100644 --- a/vendor/maxmind-db/reader/ext/config.m4 +++ b/vendor/maxmind-db/reader/ext/config.m4 @@ -1,40 +1,40 @@ -PHP_ARG_WITH(maxminddb, - [Whether to enable the MaxMind DB Reader extension], - [ --with-maxminddb Enable MaxMind DB Reader extension support]) - -PHP_ARG_ENABLE(maxminddb-debug, for MaxMind DB debug support, - [ --enable-maxminddb-debug Enable enable MaxMind DB deubg support], no, no) - -if test $PHP_MAXMINDDB != "no"; then - - AC_PATH_PROG(PKG_CONFIG, pkg-config, no) - - AC_MSG_CHECKING(for libmaxminddb) - if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libmaxminddb; then - dnl retrieve build options from pkg-config - if $PKG_CONFIG libmaxminddb --atleast-version 1.0.0; then - LIBMAXMINDDB_INC=`$PKG_CONFIG libmaxminddb --cflags` - LIBMAXMINDDB_LIB=`$PKG_CONFIG libmaxminddb --libs` - LIBMAXMINDDB_VER=`$PKG_CONFIG libmaxminddb --modversion` - AC_MSG_RESULT(found version $LIBMAXMINDDB_VER) - else - AC_MSG_ERROR(system libmaxminddb must be upgraded to version >= 1.0.0) - fi - PHP_EVAL_LIBLINE($LIBMAXMINDDB_LIB, MAXMINDDB_SHARED_LIBADD) - PHP_EVAL_INCLINE($LIBMAXMINDDB_INC) - else - AC_MSG_RESULT(pkg-config information missing) - AC_MSG_WARN(will use libmaxmxinddb from compiler default path) - - PHP_CHECK_LIBRARY(maxminddb, MMDB_open) - PHP_ADD_LIBRARY(maxminddb, 1, MAXMINDDB_SHARED_LIBADD) - fi - - if test $PHP_MAXMINDDB_DEBUG != "no"; then - CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror" - fi - - PHP_SUBST(MAXMINDDB_SHARED_LIBADD) - - PHP_NEW_EXTENSION(maxminddb, maxminddb.c, $ext_shared) -fi +PHP_ARG_WITH(maxminddb,
+ [Whether to enable the MaxMind DB Reader extension],
+ [ --with-maxminddb Enable MaxMind DB Reader extension support])
+
+PHP_ARG_ENABLE(maxminddb-debug, for MaxMind DB debug support,
+ [ --enable-maxminddb-debug Enable MaxMind DB debug support], no, no)
+
+if test $PHP_MAXMINDDB != "no"; then
+
+ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+
+ AC_MSG_CHECKING(for libmaxminddb)
+ if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libmaxminddb; then
+ dnl retrieve build options from pkg-config
+ if $PKG_CONFIG libmaxminddb --atleast-version 1.0.0; then
+ LIBMAXMINDDB_INC=`$PKG_CONFIG libmaxminddb --cflags`
+ LIBMAXMINDDB_LIB=`$PKG_CONFIG libmaxminddb --libs`
+ LIBMAXMINDDB_VER=`$PKG_CONFIG libmaxminddb --modversion`
+ AC_MSG_RESULT(found version $LIBMAXMINDDB_VER)
+ else
+ AC_MSG_ERROR(system libmaxminddb must be upgraded to version >= 1.0.0)
+ fi
+ PHP_EVAL_LIBLINE($LIBMAXMINDDB_LIB, MAXMINDDB_SHARED_LIBADD)
+ PHP_EVAL_INCLINE($LIBMAXMINDDB_INC)
+ else
+ AC_MSG_RESULT(pkg-config information missing)
+ AC_MSG_WARN(will use libmaxmxinddb from compiler default path)
+
+ PHP_CHECK_LIBRARY(maxminddb, MMDB_open)
+ PHP_ADD_LIBRARY(maxminddb, 1, MAXMINDDB_SHARED_LIBADD)
+ fi
+
+ if test $PHP_MAXMINDDB_DEBUG != "no"; then
+ CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror"
+ fi
+
+ PHP_SUBST(MAXMINDDB_SHARED_LIBADD)
+
+ PHP_NEW_EXTENSION(maxminddb, maxminddb.c, $ext_shared)
+fi
diff --git a/vendor/maxmind-db/reader/ext/config.w32 b/vendor/maxmind-db/reader/ext/config.w32 new file mode 100644 index 0000000..4eb18f8 --- /dev/null +++ b/vendor/maxmind-db/reader/ext/config.w32 @@ -0,0 +1,10 @@ +ARG_WITH("maxminddb", "Enable MaxMind DB Reader extension support", "no"); + +if (PHP_MAXMINDDB == "yes") { + if (CHECK_HEADER_ADD_INCLUDE("maxminddb.h", "CFLAGS_MAXMINDDB", PHP_MAXMINDDB + ";" + PHP_PHP_BUILD + "\\include\\maxminddb") && + CHECK_LIB("libmaxminddb.lib", "maxminddb", PHP_MAXMINDDB)) { + EXTENSION("maxminddb", "maxminddb.c"); + } else { + WARNING('Could not find maxminddb.h or libmaxminddb.lib; skipping'); + } +} diff --git a/vendor/maxmind-db/reader/ext/maxminddb.c b/vendor/maxmind-db/reader/ext/maxminddb.c index 2714608..c245b19 100644 --- a/vendor/maxmind-db/reader/ext/maxminddb.c +++ b/vendor/maxmind-db/reader/ext/maxminddb.c @@ -21,6 +21,8 @@ #include <zend.h>
#include "Zend/zend_exceptions.h"
+#include "Zend/zend_types.h"
+#include "ext/spl/spl_exceptions.h"
#include "ext/standard/info.h"
#include <maxminddb.h>
@@ -33,49 +35,49 @@ #define PHP_MAXMINDDB_NS ZEND_NS_NAME("MaxMind", "Db")
#define PHP_MAXMINDDB_READER_NS ZEND_NS_NAME(PHP_MAXMINDDB_NS, "Reader")
+#define PHP_MAXMINDDB_METADATA_NS \
+ ZEND_NS_NAME(PHP_MAXMINDDB_READER_NS, "Metadata")
#define PHP_MAXMINDDB_READER_EX_NS \
ZEND_NS_NAME(PHP_MAXMINDDB_READER_NS, "InvalidDatabaseException")
-#ifdef ZEND_ENGINE_3
#define Z_MAXMINDDB_P(zv) php_maxminddb_fetch_object(Z_OBJ_P(zv))
-#define _ZVAL_STRING ZVAL_STRING
-#define _ZVAL_STRINGL ZVAL_STRINGL
typedef size_t strsize_t;
typedef zend_object free_obj_t;
-#else
-#define Z_MAXMINDDB_P(zv) \
- (maxminddb_obj *)zend_object_store_get_object(zv TSRMLS_CC)
-#define _ZVAL_STRING(a, b) ZVAL_STRING(a, b, 1)
-#define _ZVAL_STRINGL(a, b, c) ZVAL_STRINGL(a, b, c, 1)
-typedef int strsize_t;
-typedef void free_obj_t;
-#endif
/* For PHP 8 compatibility */
-#ifndef TSRMLS_C
+#if PHP_VERSION_ID < 80000
+
+#define PROP_OBJ(zv) (zv)
+
+#else
+
+#define PROP_OBJ(zv) Z_OBJ_P(zv)
+
#define TSRMLS_C
-#endif
-#ifndef TSRMLS_CC
#define TSRMLS_CC
-#endif
-#ifndef TSRMLS_DC
#define TSRMLS_DC
+
+/* End PHP 8 compatibility */
#endif
+
#ifndef ZEND_ACC_CTOR
#define ZEND_ACC_CTOR 0
#endif
-#ifdef ZEND_ENGINE_3
+/* IS_MIXED was added in 2020 */
+#ifndef IS_MIXED
+#define IS_MIXED IS_UNDEF
+#endif
+
+/* ZEND_THIS was added in 7.4 */
+#ifndef ZEND_THIS
+#define ZEND_THIS (&EX(This))
+#endif
+
typedef struct _maxminddb_obj {
MMDB_s *mmdb;
zend_object std;
} maxminddb_obj;
-#else
-typedef struct _maxminddb_obj {
- zend_object std;
- MMDB_s *mmdb;
-} maxminddb_obj;
-#endif
PHP_FUNCTION(maxminddb);
@@ -96,7 +98,6 @@ static void handle_uint64(const MMDB_entry_data_list_s *entry_data_list, zval *z_value TSRMLS_DC);
static void handle_uint32(const MMDB_entry_data_list_s *entry_data_list,
zval *z_value TSRMLS_DC);
-static zend_class_entry *lookup_class(const char *name TSRMLS_DC);
#define CHECK_ALLOCATED(val) \
if (!val) { \
@@ -104,38 +105,16 @@ static zend_class_entry *lookup_class(const char *name TSRMLS_DC); return; \
}
-#define THROW_EXCEPTION(name, ...) \
- { \
- zend_class_entry *exception_ce = lookup_class(name TSRMLS_CC); \
- zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, __VA_ARGS__); \
- }
-
-#if PHP_VERSION_ID < 50399
-#define object_properties_init(zo, class_type) \
- { \
- zval *tmp; \
- zend_hash_copy((*zo).properties, \
- &class_type->default_properties, \
- (copy_ctor_func_t)zval_add_ref, \
- (void *)&tmp, \
- sizeof(zval *)); \
- }
-#endif
-
static zend_object_handlers maxminddb_obj_handlers;
-static zend_class_entry *maxminddb_ce;
+static zend_class_entry *maxminddb_ce, *maxminddb_exception_ce, *metadata_ce;
static inline maxminddb_obj *
php_maxminddb_fetch_object(zend_object *obj TSRMLS_DC) {
-#ifdef ZEND_ENGINE_3
return (maxminddb_obj *)((char *)(obj)-XtOffsetOf(maxminddb_obj, std));
-#else
- return (maxminddb_obj *)obj;
-#endif
}
-ZEND_BEGIN_ARG_INFO_EX(arginfo_maxmindbreader_construct, 0, 0, 1)
-ZEND_ARG_INFO(0, db_file)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_maxminddbreader_construct, 0, 0, 1)
+ZEND_ARG_TYPE_INFO(0, db_file, IS_STRING, 0)
ZEND_END_ARG_INFO()
PHP_METHOD(MaxMind_Db_Reader, __construct) {
@@ -150,37 +129,40 @@ PHP_METHOD(MaxMind_Db_Reader, __construct) { maxminddb_ce,
&db_file,
&name_len) == FAILURE) {
- THROW_EXCEPTION("InvalidArgumentException",
- "The constructor takes exactly one argument.");
return;
}
if (0 != php_check_open_basedir(db_file TSRMLS_CC) ||
0 != access(db_file, R_OK)) {
- THROW_EXCEPTION("InvalidArgumentException",
- "The file \"%s\" does not exist or is not readable.",
- db_file);
+ zend_throw_exception_ex(
+ spl_ce_InvalidArgumentException,
+ 0 TSRMLS_CC,
+ "The file \"%s\" does not exist or is not readable.",
+ db_file);
return;
}
MMDB_s *mmdb = (MMDB_s *)ecalloc(1, sizeof(MMDB_s));
- uint16_t status = MMDB_open(db_file, MMDB_MODE_MMAP, mmdb);
+ int const status = MMDB_open(db_file, MMDB_MODE_MMAP, mmdb);
if (MMDB_SUCCESS != status) {
- THROW_EXCEPTION(PHP_MAXMINDDB_READER_EX_NS,
- "Error opening database file (%s). Is this a valid "
- "MaxMind DB file?",
- db_file);
+ zend_throw_exception_ex(
+ maxminddb_exception_ce,
+ 0 TSRMLS_CC,
+ "Error opening database file (%s). Is this a valid "
+ "MaxMind DB file?",
+ db_file);
efree(mmdb);
return;
}
- maxminddb_obj *mmdb_obj = Z_MAXMINDDB_P(getThis());
+ maxminddb_obj *mmdb_obj = Z_MAXMINDDB_P(ZEND_THIS);
mmdb_obj->mmdb = mmdb;
}
-ZEND_BEGIN_ARG_INFO_EX(arginfo_maxmindbreader_get, 0, 0, 1)
-ZEND_ARG_INFO(0, ip_address)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(
+ arginfo_maxminddbreader_get, 0, 1, IS_MIXED, 1)
+ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
ZEND_END_ARG_INFO()
PHP_METHOD(MaxMind_Db_Reader, get) {
@@ -188,76 +170,75 @@ PHP_METHOD(MaxMind_Db_Reader, get) { get_record(INTERNAL_FUNCTION_PARAM_PASSTHRU, return_value, &prefix_len);
}
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(
+ arginfo_maxminddbreader_getWithPrefixLen, 0, 1, IS_ARRAY, 1)
+ZEND_ARG_TYPE_INFO(0, ip_address, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
PHP_METHOD(MaxMind_Db_Reader, getWithPrefixLen) {
- zval *record, *z_prefix_len;
-#ifdef ZEND_ENGINE_3
- zval _record, _z_prefix_len;
- record = &_record;
- z_prefix_len = &_z_prefix_len;
-#else
- ALLOC_INIT_ZVAL(record);
- ALLOC_INIT_ZVAL(z_prefix_len);
-#endif
+ zval record, z_prefix_len;
int prefix_len = 0;
- if (get_record(INTERNAL_FUNCTION_PARAM_PASSTHRU, record, &prefix_len)) {
+ if (get_record(INTERNAL_FUNCTION_PARAM_PASSTHRU, &record, &prefix_len) ==
+ FAILURE) {
return;
}
array_init(return_value);
- add_next_index_zval(return_value, record);
+ add_next_index_zval(return_value, &record);
- ZVAL_LONG(z_prefix_len, prefix_len);
- add_next_index_zval(return_value, z_prefix_len);
+ ZVAL_LONG(&z_prefix_len, prefix_len);
+ add_next_index_zval(return_value, &z_prefix_len);
}
static int
get_record(INTERNAL_FUNCTION_PARAMETERS, zval *record, int *prefix_len) {
char *ip_address = NULL;
strsize_t name_len;
- zval *_this_zval = NULL;
+ zval *this_zval = NULL;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
getThis(),
"Os",
- &_this_zval,
+ &this_zval,
maxminddb_ce,
&ip_address,
&name_len) == FAILURE) {
- THROW_EXCEPTION("InvalidArgumentException",
- "Method takes exactly one argument.");
- return 1;
+ return FAILURE;
}
- const maxminddb_obj *mmdb_obj = (maxminddb_obj *)Z_MAXMINDDB_P(getThis());
+ const maxminddb_obj *mmdb_obj = (maxminddb_obj *)Z_MAXMINDDB_P(ZEND_THIS);
MMDB_s *mmdb = mmdb_obj->mmdb;
if (NULL == mmdb) {
- THROW_EXCEPTION("BadMethodCallException",
- "Attempt to read from a closed MaxMind DB.");
- return 1;
+ zend_throw_exception_ex(spl_ce_BadMethodCallException,
+ 0 TSRMLS_CC,
+ "Attempt to read from a closed MaxMind DB.");
+ return FAILURE;
}
struct addrinfo hints = {
.ai_family = AF_UNSPEC,
.ai_flags = AI_NUMERICHOST,
- // We set ai_socktype so that we only get one result back
+ /* We set ai_socktype so that we only get one result back */
.ai_socktype = SOCK_STREAM};
struct addrinfo *addresses = NULL;
int gai_status = getaddrinfo(ip_address, NULL, &hints, &addresses);
if (gai_status) {
- THROW_EXCEPTION("InvalidArgumentException",
- "The value \"%s\" is not a valid IP address.",
- ip_address);
- return 1;
+ zend_throw_exception_ex(spl_ce_InvalidArgumentException,
+ 0 TSRMLS_CC,
+ "The value \"%s\" is not a valid IP address.",
+ ip_address);
+ return FAILURE;
}
if (!addresses || !addresses->ai_addr) {
- THROW_EXCEPTION(
- "InvalidArgumentException",
+ zend_throw_exception_ex(
+ spl_ce_InvalidArgumentException,
+ 0 TSRMLS_CC,
"getaddrinfo was successful but failed to set the addrinfo");
- return 1;
+ return FAILURE;
}
int sa_family = addresses->ai_addr->sa_family;
@@ -269,132 +250,127 @@ get_record(INTERNAL_FUNCTION_PARAMETERS, zval *record, int *prefix_len) { freeaddrinfo(addresses);
if (MMDB_SUCCESS != mmdb_error) {
- char *exception_name;
+ zend_class_entry *ex;
if (MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR == mmdb_error) {
- exception_name = "InvalidArgumentException";
+ ex = spl_ce_InvalidArgumentException;
} else {
- exception_name = PHP_MAXMINDDB_READER_EX_NS;
+ ex = maxminddb_exception_ce;
}
- THROW_EXCEPTION(exception_name,
- "Error looking up %s. %s",
- ip_address,
- MMDB_strerror(mmdb_error));
- return 1;
+ zend_throw_exception_ex(ex,
+ 0 TSRMLS_CC,
+ "Error looking up %s. %s",
+ ip_address,
+ MMDB_strerror(mmdb_error));
+ return FAILURE;
}
*prefix_len = result.netmask;
if (sa_family == AF_INET && mmdb->metadata.ip_version == 6) {
- // We return the prefix length given the IPv4 address. If there is
- // no IPv4 subtree, we return a prefix length of 0.
+ /* We return the prefix length given the IPv4 address. If there is
+ no IPv4 subtree, we return a prefix length of 0. */
*prefix_len = *prefix_len >= 96 ? *prefix_len - 96 : 0;
}
if (!result.found_entry) {
ZVAL_NULL(record);
- return 0;
+ return SUCCESS;
}
MMDB_entry_data_list_s *entry_data_list = NULL;
int status = MMDB_get_entry_data_list(&result.entry, &entry_data_list);
if (MMDB_SUCCESS != status) {
- THROW_EXCEPTION(PHP_MAXMINDDB_READER_EX_NS,
- "Error while looking up data for %s. %s",
- ip_address,
- MMDB_strerror(status));
+ zend_throw_exception_ex(maxminddb_exception_ce,
+ 0 TSRMLS_CC,
+ "Error while looking up data for %s. %s",
+ ip_address,
+ MMDB_strerror(status));
MMDB_free_entry_data_list(entry_data_list);
- return 1;
+ return FAILURE;
} else if (NULL == entry_data_list) {
- THROW_EXCEPTION(PHP_MAXMINDDB_READER_EX_NS,
- "Error while looking up data for %s. Your database may "
- "be corrupt or you have found a bug in libmaxminddb.",
- ip_address);
- return 1;
+ zend_throw_exception_ex(
+ maxminddb_exception_ce,
+ 0 TSRMLS_CC,
+ "Error while looking up data for %s. Your database may "
+ "be corrupt or you have found a bug in libmaxminddb.",
+ ip_address);
+ return FAILURE;
}
- handle_entry_data_list(entry_data_list, record TSRMLS_CC);
+ const MMDB_entry_data_list_s *rv =
+ handle_entry_data_list(entry_data_list, record TSRMLS_CC);
+ if (rv == NULL) {
+ /* We should have already thrown the exception in handle_entry_data_list
+ */
+ return FAILURE;
+ }
MMDB_free_entry_data_list(entry_data_list);
- return 0;
+ return SUCCESS;
}
-ZEND_BEGIN_ARG_INFO_EX(arginfo_maxmindbreader_void, 0, 0, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_maxminddbreader_void, 0, 0, 0)
ZEND_END_ARG_INFO()
PHP_METHOD(MaxMind_Db_Reader, metadata) {
- if (ZEND_NUM_ARGS() != 0) {
- THROW_EXCEPTION("InvalidArgumentException",
- "Method takes no arguments.");
+ zval *this_zval = NULL;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ getThis(),
+ "O",
+ &this_zval,
+ maxminddb_ce) == FAILURE) {
return;
}
const maxminddb_obj *const mmdb_obj =
- (maxminddb_obj *)Z_MAXMINDDB_P(getThis());
+ (maxminddb_obj *)Z_MAXMINDDB_P(this_zval);
if (NULL == mmdb_obj->mmdb) {
- THROW_EXCEPTION("BadMethodCallException",
- "Attempt to read from a closed MaxMind DB.");
+ zend_throw_exception_ex(spl_ce_BadMethodCallException,
+ 0 TSRMLS_CC,
+ "Attempt to read from a closed MaxMind DB.");
return;
}
- const char *const name = ZEND_NS_NAME(PHP_MAXMINDDB_READER_NS, "Metadata");
- zend_class_entry *metadata_ce = lookup_class(name TSRMLS_CC);
-
object_init_ex(return_value, metadata_ce);
-#ifdef ZEND_ENGINE_3
- zval _metadata_array;
- zval *metadata_array = &_metadata_array;
- ZVAL_NULL(metadata_array);
-#else
- zval *metadata_array;
- ALLOC_INIT_ZVAL(metadata_array);
-#endif
-
MMDB_entry_data_list_s *entry_data_list;
MMDB_get_metadata_as_entry_data_list(mmdb_obj->mmdb, &entry_data_list);
- handle_entry_data_list(entry_data_list, metadata_array TSRMLS_CC);
+ zval metadata_array;
+ const MMDB_entry_data_list_s *rv =
+ handle_entry_data_list(entry_data_list, &metadata_array TSRMLS_CC);
+ if (rv == NULL) {
+ return;
+ }
MMDB_free_entry_data_list(entry_data_list);
-#if PHP_VERSION_ID >= 80000
- zend_call_method_with_1_params(Z_OBJ_P(return_value),
+ zend_call_method_with_1_params(PROP_OBJ(return_value),
metadata_ce,
&metadata_ce->constructor,
ZEND_CONSTRUCTOR_FUNC_NAME,
NULL,
- metadata_array);
- zval_ptr_dtor(metadata_array);
-#elif defined(ZEND_ENGINE_3)
- zend_call_method_with_1_params(return_value,
- metadata_ce,
- &metadata_ce->constructor,
- ZEND_CONSTRUCTOR_FUNC_NAME,
- NULL,
- metadata_array);
- zval_ptr_dtor(metadata_array);
-#else
- zend_call_method_with_1_params(&return_value,
- metadata_ce,
- &metadata_ce->constructor,
- ZEND_CONSTRUCTOR_FUNC_NAME,
- NULL,
- metadata_array);
+ &metadata_array);
zval_ptr_dtor(&metadata_array);
-#endif
}
PHP_METHOD(MaxMind_Db_Reader, close) {
- if (ZEND_NUM_ARGS() != 0) {
- THROW_EXCEPTION("InvalidArgumentException",
- "Method takes no arguments.");
+ zval *this_zval = NULL;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ getThis(),
+ "O",
+ &this_zval,
+ maxminddb_ce) == FAILURE) {
return;
}
- maxminddb_obj *mmdb_obj = (maxminddb_obj *)Z_MAXMINDDB_P(getThis());
+ maxminddb_obj *mmdb_obj = (maxminddb_obj *)Z_MAXMINDDB_P(this_zval);
if (NULL == mmdb_obj->mmdb) {
- THROW_EXCEPTION("BadMethodCallException",
- "Attempt to close a closed MaxMind DB.");
+ zend_throw_exception_ex(spl_ce_BadMethodCallException,
+ 0 TSRMLS_CC,
+ "Attempt to close a closed MaxMind DB.");
return;
}
MMDB_close(mmdb_obj->mmdb);
@@ -411,14 +387,14 @@ handle_entry_data_list(const MMDB_entry_data_list_s *entry_data_list, case MMDB_DATA_TYPE_ARRAY:
return handle_array(entry_data_list, z_value TSRMLS_CC);
case MMDB_DATA_TYPE_UTF8_STRING:
- _ZVAL_STRINGL(z_value,
- (char *)entry_data_list->entry_data.utf8_string,
- entry_data_list->entry_data.data_size);
+ ZVAL_STRINGL(z_value,
+ entry_data_list->entry_data.utf8_string,
+ entry_data_list->entry_data.data_size);
break;
case MMDB_DATA_TYPE_BYTES:
- _ZVAL_STRINGL(z_value,
- (char *)entry_data_list->entry_data.bytes,
- entry_data_list->entry_data.data_size);
+ ZVAL_STRINGL(z_value,
+ (char const *)entry_data_list->entry_data.bytes,
+ entry_data_list->entry_data.data_size);
break;
case MMDB_DATA_TYPE_DOUBLE:
ZVAL_DOUBLE(z_value, entry_data_list->entry_data.double_value);
@@ -445,9 +421,10 @@ handle_entry_data_list(const MMDB_entry_data_list_s *entry_data_list, ZVAL_LONG(z_value, entry_data_list->entry_data.int32);
break;
default:
- THROW_EXCEPTION(PHP_MAXMINDDB_READER_EX_NS,
- "Invalid data type arguments: %d",
- entry_data_list->entry_data.type);
+ zend_throw_exception_ex(maxminddb_exception_ce,
+ 0 TSRMLS_CC,
+ "Invalid data type arguments: %d",
+ entry_data_list->entry_data.type);
return NULL;
}
return entry_data_list;
@@ -459,30 +436,26 @@ handle_map(const MMDB_entry_data_list_s *entry_data_list, array_init(z_value);
const uint32_t map_size = entry_data_list->entry_data.data_size;
- uint i;
+ uint32_t i;
for (i = 0; i < map_size && entry_data_list; i++) {
entry_data_list = entry_data_list->next;
- char *key = estrndup((char *)entry_data_list->entry_data.utf8_string,
+ char *key = estrndup(entry_data_list->entry_data.utf8_string,
entry_data_list->entry_data.data_size);
if (NULL == key) {
- THROW_EXCEPTION(PHP_MAXMINDDB_READER_EX_NS,
- "Invalid data type arguments");
+ zend_throw_exception_ex(maxminddb_exception_ce,
+ 0 TSRMLS_CC,
+ "Invalid data type arguments");
return NULL;
}
entry_data_list = entry_data_list->next;
-#ifdef ZEND_ENGINE_3
- zval _new_value;
- zval *new_value = &_new_value;
- ZVAL_NULL(new_value);
-#else
- zval *new_value;
- ALLOC_INIT_ZVAL(new_value);
-#endif
+ zval new_value;
entry_data_list =
- handle_entry_data_list(entry_data_list, new_value TSRMLS_CC);
- add_assoc_zval(z_value, key, new_value);
+ handle_entry_data_list(entry_data_list, &new_value TSRMLS_CC);
+ if (entry_data_list != NULL) {
+ add_assoc_zval(z_value, key, &new_value);
+ }
efree(key);
}
return entry_data_list;
@@ -495,20 +468,15 @@ handle_array(const MMDB_entry_data_list_s *entry_data_list, array_init(z_value);
- uint i;
+ uint32_t i;
for (i = 0; i < size && entry_data_list; i++) {
entry_data_list = entry_data_list->next;
-#ifdef ZEND_ENGINE_3
- zval _new_value;
- zval *new_value = &_new_value;
- ZVAL_NULL(new_value);
-#else
- zval *new_value;
- ALLOC_INIT_ZVAL(new_value);
-#endif
+ zval new_value;
entry_data_list =
- handle_entry_data_list(entry_data_list, new_value TSRMLS_CC);
- add_next_index_zval(z_value, new_value);
+ handle_entry_data_list(entry_data_list, &new_value TSRMLS_CC);
+ if (entry_data_list != NULL) {
+ add_next_index_zval(z_value, &new_value);
+ }
}
return entry_data_list;
}
@@ -535,7 +503,7 @@ static void handle_uint128(const MMDB_entry_data_list_s *entry_data_list, spprintf(&num_str, 0, "0x%016" PRIX64 "%016" PRIX64, high, low);
CHECK_ALLOCATED(num_str);
- _ZVAL_STRING(z_value, num_str);
+ ZVAL_STRING(z_value, num_str);
efree(num_str);
}
@@ -556,7 +524,7 @@ static void handle_uint32(const MMDB_entry_data_list_s *entry_data_list, spprintf(&int_str, 0, "%" PRIu32, val);
CHECK_ALLOCATED(int_str);
- _ZVAL_STRING(z_value, int_str);
+ ZVAL_STRING(z_value, int_str);
efree(int_str);
#endif
}
@@ -578,29 +546,11 @@ static void handle_uint64(const MMDB_entry_data_list_s *entry_data_list, spprintf(&int_str, 0, "%" PRIu64, val);
CHECK_ALLOCATED(int_str);
- _ZVAL_STRING(z_value, int_str);
+ ZVAL_STRING(z_value, int_str);
efree(int_str);
#endif
}
-static zend_class_entry *lookup_class(const char *name TSRMLS_DC) {
-#ifdef ZEND_ENGINE_3
- zend_string *n = zend_string_init(name, strlen(name), 0);
- zend_class_entry *ce = zend_lookup_class(n);
- zend_string_release(n);
- if (NULL == ce) {
- zend_error(E_ERROR, "Class %s not found", name);
- }
- return ce;
-#else
- zend_class_entry **ce;
- if (FAILURE == zend_lookup_class(name, strlen(name), &ce TSRMLS_CC)) {
- zend_error(E_ERROR, "Class %s not found", name);
- }
- return *ce;
-#endif
-}
-
static void maxminddb_free_storage(free_obj_t *object TSRMLS_DC) {
maxminddb_obj *obj =
php_maxminddb_fetch_object((zend_object *)object TSRMLS_CC);
@@ -610,12 +560,8 @@ static void maxminddb_free_storage(free_obj_t *object TSRMLS_DC) { }
zend_object_std_dtor(&obj->std TSRMLS_CC);
-#ifndef ZEND_ENGINE_3
- efree(object);
-#endif
}
-#ifdef ZEND_ENGINE_3
static zend_object *maxminddb_create_handler(zend_class_entry *type TSRMLS_DC) {
maxminddb_obj *obj = (maxminddb_obj *)ecalloc(1, sizeof(maxminddb_obj));
zend_object_std_init(&obj->std, type TSRMLS_CC);
@@ -625,49 +571,210 @@ static zend_object *maxminddb_create_handler(zend_class_entry *type TSRMLS_DC) { return &obj->std;
}
-#else
-static zend_object_value
-maxminddb_create_handler(zend_class_entry *type TSRMLS_DC) {
- zend_object_value retval;
- maxminddb_obj *obj = (maxminddb_obj *)ecalloc(1, sizeof(maxminddb_obj));
- zend_object_std_init(&obj->std, type TSRMLS_CC);
- object_properties_init(&(obj->std), type);
+/* clang-format off */
+static zend_function_entry maxminddb_methods[] = {
+ PHP_ME(MaxMind_Db_Reader, __construct, arginfo_maxminddbreader_construct,
+ ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
+ PHP_ME(MaxMind_Db_Reader, close, arginfo_maxminddbreader_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MaxMind_Db_Reader, get, arginfo_maxminddbreader_get, ZEND_ACC_PUBLIC)
+ PHP_ME(MaxMind_Db_Reader, getWithPrefixLen, arginfo_maxminddbreader_getWithPrefixLen, ZEND_ACC_PUBLIC)
+ PHP_ME(MaxMind_Db_Reader, metadata, arginfo_maxminddbreader_void, ZEND_ACC_PUBLIC)
+ { NULL, NULL, NULL }
+};
+/* clang-format on */
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_metadata_construct, 0, 0, 1)
+ZEND_ARG_TYPE_INFO(0, metadata, IS_ARRAY, 0)
+ZEND_END_ARG_INFO()
+
+PHP_METHOD(MaxMind_Db_Reader_Metadata, __construct) {
+ zval *object = NULL;
+ zval *metadata_array = NULL;
+ zend_long node_count = 0;
+ zend_long record_size = 0;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ getThis(),
+ "Oa",
+ &object,
+ metadata_ce,
+ &metadata_array) == FAILURE) {
+ return;
+ }
+
+ zval *tmp = NULL;
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "binary_format_major_version",
+ sizeof("binary_format_major_version") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "binaryFormatMajorVersion",
+ sizeof("binaryFormatMajorVersion") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "binary_format_minor_version",
+ sizeof("binary_format_minor_version") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "binaryFormatMinorVersion",
+ sizeof("binaryFormatMinorVersion") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "build_epoch",
+ sizeof("build_epoch") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "buildEpoch",
+ sizeof("buildEpoch") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "database_type",
+ sizeof("database_type") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "databaseType",
+ sizeof("databaseType") - 1,
+ tmp);
+ }
- retval.handle = zend_objects_store_put(
- obj, NULL, maxminddb_free_storage, NULL TSRMLS_CC);
- retval.handlers = &maxminddb_obj_handlers;
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "description",
+ sizeof("description") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "description",
+ sizeof("description") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "ip_version",
+ sizeof("ip_version") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "ipVersion",
+ sizeof("ipVersion") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(
+ HASH_OF(metadata_array), "languages", sizeof("languages") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "languages",
+ sizeof("languages") - 1,
+ tmp);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "record_size",
+ sizeof("record_size") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "recordSize",
+ sizeof("recordSize") - 1,
+ tmp);
+ if (Z_TYPE_P(tmp) == IS_LONG) {
+ record_size = Z_LVAL_P(tmp);
+ }
+ }
- return retval;
+ if (record_size != 0) {
+ zend_update_property_long(metadata_ce,
+ PROP_OBJ(object),
+ "nodeByteSize",
+ sizeof("nodeByteSize") - 1,
+ record_size / 4);
+ }
+
+ if ((tmp = zend_hash_str_find(HASH_OF(metadata_array),
+ "node_count",
+ sizeof("node_count") - 1))) {
+ zend_update_property(metadata_ce,
+ PROP_OBJ(object),
+ "nodeCount",
+ sizeof("nodeCount") - 1,
+ tmp);
+ if (Z_TYPE_P(tmp) == IS_LONG) {
+ node_count = Z_LVAL_P(tmp);
+ }
+ }
+
+ if (record_size != 0) {
+ zend_update_property_long(metadata_ce,
+ PROP_OBJ(object),
+ "searchTreeSize",
+ sizeof("searchTreeSize") - 1,
+ record_size * node_count / 4);
+ }
}
-#endif
// clang-format off
-static zend_function_entry maxminddb_methods[] = {
- PHP_ME(MaxMind_Db_Reader, __construct, arginfo_maxmindbreader_construct,
- ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
- PHP_ME(MaxMind_Db_Reader, close, arginfo_maxmindbreader_void, ZEND_ACC_PUBLIC)
- PHP_ME(MaxMind_Db_Reader, get, arginfo_maxmindbreader_get, ZEND_ACC_PUBLIC)
- PHP_ME(MaxMind_Db_Reader, getWithPrefixLen, arginfo_maxmindbreader_get, ZEND_ACC_PUBLIC)
- PHP_ME(MaxMind_Db_Reader, metadata, arginfo_maxmindbreader_void, ZEND_ACC_PUBLIC)
- { NULL, NULL, NULL }
+static zend_function_entry metadata_methods[] = {
+ PHP_ME(MaxMind_Db_Reader_Metadata, __construct, arginfo_metadata_construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
+ {NULL, NULL, NULL}
};
// clang-format on
PHP_MINIT_FUNCTION(maxminddb) {
zend_class_entry ce;
+ INIT_CLASS_ENTRY(ce, PHP_MAXMINDDB_READER_EX_NS, NULL);
+ maxminddb_exception_ce =
+ zend_register_internal_class_ex(&ce, zend_ce_exception);
+
INIT_CLASS_ENTRY(ce, PHP_MAXMINDDB_READER_NS, maxminddb_methods);
maxminddb_ce = zend_register_internal_class(&ce TSRMLS_CC);
maxminddb_ce->create_object = maxminddb_create_handler;
+
+ INIT_CLASS_ENTRY(ce, PHP_MAXMINDDB_METADATA_NS, metadata_methods);
+ metadata_ce = zend_register_internal_class(&ce TSRMLS_CC);
+ zend_declare_property_null(metadata_ce,
+ "binaryFormatMajorVersion",
+ sizeof("binaryFormatMajorVersion") - 1,
+ ZEND_ACC_PUBLIC);
+ zend_declare_property_null(metadata_ce,
+ "binaryFormatMinorVersion",
+ sizeof("binaryFormatMinorVersion") - 1,
+ ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "buildEpoch", sizeof("buildEpoch") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(metadata_ce,
+ "databaseType",
+ sizeof("databaseType") - 1,
+ ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "description", sizeof("description") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "ipVersion", sizeof("ipVersion") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "languages", sizeof("languages") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(metadata_ce,
+ "nodeByteSize",
+ sizeof("nodeByteSize") - 1,
+ ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "nodeCount", sizeof("nodeCount") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(
+ metadata_ce, "recordSize", sizeof("recordSize") - 1, ZEND_ACC_PUBLIC);
+ zend_declare_property_null(metadata_ce,
+ "searchTreeSize",
+ sizeof("searchTreeSize") - 1,
+ ZEND_ACC_PUBLIC);
+
memcpy(&maxminddb_obj_handlers,
zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
maxminddb_obj_handlers.clone_obj = NULL;
-#ifdef ZEND_ENGINE_3
maxminddb_obj_handlers.offset = XtOffsetOf(maxminddb_obj, std);
maxminddb_obj_handlers.free_obj = maxminddb_free_storage;
-#endif
zend_declare_class_constant_string(maxminddb_ce,
"MMDB_LIB_VERSION",
sizeof("MMDB_LIB_VERSION") - 1,
diff --git a/vendor/maxmind-db/reader/ext/php_maxminddb.h b/vendor/maxmind-db/reader/ext/php_maxminddb.h index b219777..24346f2 100644 --- a/vendor/maxmind-db/reader/ext/php_maxminddb.h +++ b/vendor/maxmind-db/reader/ext/php_maxminddb.h @@ -15,7 +15,7 @@ #ifndef PHP_MAXMINDDB_H
#define PHP_MAXMINDDB_H 1
-#define PHP_MAXMINDDB_VERSION "1.10.1"
+#define PHP_MAXMINDDB_VERSION "1.11.1"
#define PHP_MAXMINDDB_EXTNAME "maxminddb"
extern zend_module_entry maxminddb_module_entry;
diff --git a/vendor/maxmind-db/reader/package.xml b/vendor/maxmind-db/reader/package.xml index 2beaf37..796b5ff 100644 --- a/vendor/maxmind-db/reader/package.xml +++ b/vendor/maxmind-db/reader/package.xml @@ -14,19 +14,19 @@ <email>goschwald@maxmind.com</email>
<active>yes</active>
</lead>
- <date>2021-04-14</date>
+ <date>2023-12-01</date>
<version>
- <release>1.10.1</release>
- <api>1.10.1</api>
+ <release>1.11.1</release>
+ <api>1.11.1</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="https://github.com/maxmind/MaxMind-DB-Reader-php/blob/main/LICENSE">Apache License 2.0</license>
- <notes>* Fix a `TypeError` exception in the pure PHP reader when using large
- databases on 32-bit PHP builds with the `bcmath` extension. Reported
- by dodo1708. GitHub #124.</notes>
+ <notes>* Resolve warnings when compiling the C extension.
+* Fix various type issues detected by PHPStan level. Pull request by
+ LauraTaylorUK. GitHub #160.</notes>
<contents>
<dir name="/">
<file role="doc" name="LICENSE"/>
diff --git a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php index 85457c5..807fe62 100644 --- a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php +++ b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php @@ -1,15 +1,13 @@ <?php
+declare(strict_types=1);
+
namespace MaxMind\Db;
-use BadMethodCallException;
-use Exception;
-use InvalidArgumentException;
use MaxMind\Db\Reader\Decoder;
use MaxMind\Db\Reader\InvalidDatabaseException;
use MaxMind\Db\Reader\Metadata;
use MaxMind\Db\Reader\Util;
-use UnexpectedValueException;
/**
* Instances of this class provide a reader for the MaxMind DB format. IP
@@ -17,15 +15,49 @@ use UnexpectedValueException; */
class Reader
{
+ /**
+ * @var int
+ */
private static $DATA_SECTION_SEPARATOR_SIZE = 16;
+
+ /**
+ * @var string
+ */
private static $METADATA_START_MARKER = "\xAB\xCD\xEFMaxMind.com";
+
+ /**
+ * @var int<0, max>
+ */
private static $METADATA_START_MARKER_LENGTH = 14;
- private static $METADATA_MAX_SIZE = 131072; // 128 * 1024 = 128KB
+ /**
+ * @var int
+ */
+ private static $METADATA_MAX_SIZE = 131072; // 128 * 1024 = 128KiB
+
+ /**
+ * @var Decoder
+ */
private $decoder;
+
+ /**
+ * @var resource
+ */
private $fileHandle;
+
+ /**
+ * @var int
+ */
private $fileSize;
+
+ /**
+ * @var int
+ */
private $ipV4Start;
+
+ /**
+ * @var Metadata
+ */
private $metadata;
/**
@@ -35,40 +67,38 @@ class Reader * @param string $database
* the MaxMind DB file to use
*
- * @throws InvalidArgumentException for invalid database path or unknown arguments
- * @throws \MaxMind\Db\Reader\InvalidDatabaseException
- * if the database is invalid or there is an error reading
- * from it
+ * @throws \InvalidArgumentException for invalid database path or unknown arguments
+ * @throws InvalidDatabaseException
+ * if the database is invalid or there is an error reading
+ * from it
*/
- public function __construct($database)
+ public function __construct(string $database)
{
if (\func_num_args() !== 1) {
- throw new InvalidArgumentException(
- 'The constructor takes exactly one argument.'
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
);
}
- if (!is_readable($database)) {
- throw new InvalidArgumentException(
+ $fileHandle = @fopen($database, 'rb');
+ if ($fileHandle === false) {
+ throw new \InvalidArgumentException(
"The file \"$database\" does not exist or is not readable."
);
}
- $this->fileHandle = @fopen($database, 'rb');
- if ($this->fileHandle === false) {
- throw new InvalidArgumentException(
- "Error opening \"$database\"."
- );
- }
- $this->fileSize = @filesize($database);
- if ($this->fileSize === false) {
- throw new UnexpectedValueException(
+ $this->fileHandle = $fileHandle;
+
+ $fileSize = @filesize($database);
+ if ($fileSize === false) {
+ throw new \UnexpectedValueException(
"Error determining the size of \"$database\"."
);
}
+ $this->fileSize = $fileSize;
$start = $this->findMetadataStart($database);
$metadataDecoder = new Decoder($this->fileHandle, $start);
- list($metadataArray) = $metadataDecoder->decode($start);
+ [$metadataArray] = $metadataDecoder->decode($start);
$this->metadata = new Metadata($metadataArray);
$this->decoder = new Decoder(
$this->fileHandle,
@@ -83,22 +113,22 @@ class Reader * @param string $ipAddress
* the IP address to look up
*
- * @throws BadMethodCallException if this method is called on a closed database
- * @throws InvalidArgumentException if something other than a single IP address is passed to the method
+ * @throws \BadMethodCallException if this method is called on a closed database
+ * @throws \InvalidArgumentException if something other than a single IP address is passed to the method
* @throws InvalidDatabaseException
- * if the database is invalid or there is an error reading
- * from it
+ * if the database is invalid or there is an error reading
+ * from it
*
* @return mixed the record for the IP address
*/
- public function get($ipAddress)
+ public function get(string $ipAddress)
{
if (\func_num_args() !== 1) {
- throw new InvalidArgumentException(
- 'Method takes exactly one argument.'
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
);
}
- list($record) = $this->getWithPrefixLen($ipAddress);
+ [$record] = $this->getWithPrefixLen($ipAddress);
return $record;
}
@@ -109,36 +139,30 @@ class Reader * @param string $ipAddress
* the IP address to look up
*
- * @throws BadMethodCallException if this method is called on a closed database
- * @throws InvalidArgumentException if something other than a single IP address is passed to the method
+ * @throws \BadMethodCallException if this method is called on a closed database
+ * @throws \InvalidArgumentException if something other than a single IP address is passed to the method
* @throws InvalidDatabaseException
- * if the database is invalid or there is an error reading
- * from it
+ * if the database is invalid or there is an error reading
+ * from it
*
* @return array an array where the first element is the record and the
* second the network prefix length for the record
*/
- public function getWithPrefixLen($ipAddress)
+ public function getWithPrefixLen(string $ipAddress): array
{
if (\func_num_args() !== 1) {
- throw new InvalidArgumentException(
- 'Method takes exactly one argument.'
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
);
}
if (!\is_resource($this->fileHandle)) {
- throw new BadMethodCallException(
+ throw new \BadMethodCallException(
'Attempt to read from a closed MaxMind DB.'
);
}
- if (!filter_var($ipAddress, FILTER_VALIDATE_IP)) {
- throw new InvalidArgumentException(
- "The value \"$ipAddress\" is not a valid IP address."
- );
- }
-
- list($pointer, $prefixLen) = $this->findAddressInTree($ipAddress);
+ [$pointer, $prefixLen] = $this->findAddressInTree($ipAddress);
if ($pointer === 0) {
return [null, $prefixLen];
}
@@ -146,9 +170,21 @@ class Reader return [$this->resolveDataPointer($pointer), $prefixLen];
}
- private function findAddressInTree($ipAddress)
+ private function findAddressInTree(string $ipAddress): array
{
- $rawAddress = unpack('C*', inet_pton($ipAddress));
+ $packedAddr = @inet_pton($ipAddress);
+ if ($packedAddr === false) {
+ throw new \InvalidArgumentException(
+ "The value \"$ipAddress\" is not a valid IP address."
+ );
+ }
+
+ $rawAddress = unpack('C*', $packedAddr);
+ if ($rawAddress === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack the unsigned char of the packed in_addr representation.'
+ );
+ }
$bitCount = \count($rawAddress) * 8;
@@ -165,7 +201,7 @@ class Reader $node = $this->ipV4Start;
}
} elseif ($metadata->ipVersion === 4 && $bitCount === 128) {
- throw new InvalidArgumentException(
+ throw new \InvalidArgumentException(
"Error looking up $ipAddress. You attempted to look up an"
. ' IPv6 address in an IPv4-only database.'
);
@@ -182,14 +218,18 @@ class Reader if ($node === $nodeCount) {
// Record is empty
return [0, $i];
- } elseif ($node > $nodeCount) {
+ }
+ if ($node > $nodeCount) {
// Record is a data pointer
return [$node, $i];
}
- throw new InvalidDatabaseException('Something bad happened');
+
+ throw new InvalidDatabaseException(
+ 'Invalid or corrupt database. Maximum search depth reached without finding a leaf node'
+ );
}
- private function ipV4StartNode()
+ private function ipV4StartNode(): int
{
// If we have an IPv4 database, the start node is the first node
if ($this->metadata->ipVersion === 4) {
@@ -205,16 +245,23 @@ class Reader return $node;
}
- private function readNode($nodeNumber, $index)
+ private function readNode(int $nodeNumber, int $index): int
{
$baseOffset = $nodeNumber * $this->metadata->nodeByteSize;
switch ($this->metadata->recordSize) {
case 24:
$bytes = Util::read($this->fileHandle, $baseOffset + $index * 3, 3);
- list(, $node) = unpack('N', "\x00" . $bytes);
+ $rc = unpack('N', "\x00" . $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack the unsigned long of the node.'
+ );
+ }
+ [, $node] = $rc;
return $node;
+
case 28:
$bytes = Util::read($this->fileHandle, $baseOffset + 3 * $index, 4);
if ($index === 0) {
@@ -222,14 +269,28 @@ class Reader } else {
$middle = 0x0F & \ord($bytes[0]);
}
- list(, $node) = unpack('N', \chr($middle) . substr($bytes, $index, 3));
+ $rc = unpack('N', \chr($middle) . substr($bytes, $index, 3));
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack the unsigned long of the node.'
+ );
+ }
+ [, $node] = $rc;
return $node;
+
case 32:
$bytes = Util::read($this->fileHandle, $baseOffset + $index * 4, 4);
- list(, $node) = unpack('N', $bytes);
+ $rc = unpack('N', $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack the unsigned long of the node.'
+ );
+ }
+ [, $node] = $rc;
return $node;
+
default:
throw new InvalidDatabaseException(
'Unknown record size: '
@@ -238,7 +299,10 @@ class Reader }
}
- private function resolveDataPointer($pointer)
+ /**
+ * @return mixed
+ */
+ private function resolveDataPointer(int $pointer)
{
$resolved = $pointer - $this->metadata->nodeCount
+ $this->metadata->searchTreeSize;
@@ -248,7 +312,7 @@ class Reader );
}
- list($data) = $this->decoder->decode($resolved);
+ [$data] = $this->decoder->decode($resolved);
return $data;
}
@@ -258,10 +322,15 @@ class Reader * are much faster algorithms (e.g., Boyer-Moore) for this if speed is ever
* an issue, but I suspect it won't be.
*/
- private function findMetadataStart($filename)
+ private function findMetadataStart(string $filename): int
{
$handle = $this->fileHandle;
$fstat = fstat($handle);
+ if ($fstat === false) {
+ throw new InvalidDatabaseException(
+ "Error getting file information ($filename)."
+ );
+ }
$fileSize = $fstat['size'];
$marker = self::$METADATA_START_MARKER;
$markerLength = self::$METADATA_START_MARKER_LENGTH;
@@ -278,6 +347,7 @@ class Reader return $offset + $markerLength;
}
}
+
throw new InvalidDatabaseException(
"Error opening database file ($filename). " .
'Is this a valid MaxMind DB file?'
@@ -285,40 +355,46 @@ class Reader }
/**
- * @throws InvalidArgumentException if arguments are passed to the method
- * @throws BadMethodCallException if the database has been closed
+ * @throws \InvalidArgumentException if arguments are passed to the method
+ * @throws \BadMethodCallException if the database has been closed
*
* @return Metadata object for the database
*/
- public function metadata()
+ public function metadata(): Metadata
{
if (\func_num_args()) {
- throw new InvalidArgumentException(
- 'Method takes no arguments.'
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args())
);
}
// Not technically required, but this makes it consistent with
// C extension and it allows us to change our implementation later.
if (!\is_resource($this->fileHandle)) {
- throw new BadMethodCallException(
+ throw new \BadMethodCallException(
'Attempt to read from a closed MaxMind DB.'
);
}
- return $this->metadata;
+ return clone $this->metadata;
}
/**
* Closes the MaxMind DB and returns resources to the system.
*
- * @throws Exception
- * if an I/O error occurs
+ * @throws \Exception
+ * if an I/O error occurs
*/
- public function close()
+ public function close(): void
{
+ if (\func_num_args()) {
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 0 parameters, %d given', __METHOD__, \func_num_args())
+ );
+ }
+
if (!\is_resource($this->fileHandle)) {
- throw new BadMethodCallException(
+ throw new \BadMethodCallException(
'Attempt to close a closed MaxMind DB.'
);
}
diff --git a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php index 8f451b8..8786a01 100644 --- a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php +++ b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php @@ -5,14 +5,6 @@ declare(strict_types=1); namespace MaxMind\Db\Reader;
// @codingStandardsIgnoreLine
-use RuntimeException;
-
-/*
- * @ignore
- *
- * We subtract 1 from the log to protect against precision loss.
- */
-\define(__NAMESPACE__ . '\_MM_MAX_INT_BYTES', (int) ((log(\PHP_INT_MAX, 2) - 1) / 8));
class Decoder
{
@@ -20,20 +12,19 @@ class Decoder * @var resource
*/
private $fileStream;
+
/**
* @var int
*/
private $pointerBase;
- /**
- * @var float
- */
- private $pointerBaseByteSize;
+
/**
* This is only used for unit testing.
*
* @var bool
*/
private $pointerTestHack;
+
/**
* @var bool
*/
@@ -51,8 +42,8 @@ class Decoder private const _UINT64 = 9;
private const _UINT128 = 10;
private const _ARRAY = 11;
- private const _CONTAINER = 12;
- private const _END_MARKER = 13;
+ // 12 is the container type
+ // 13 is the end marker type
private const _BOOLEAN = 14;
private const _FLOAT = 15;
@@ -67,7 +58,6 @@ class Decoder $this->fileStream = $fileStream;
$this->pointerBase = $pointerBase;
- $this->pointerBaseByteSize = $pointerBase > 0 ? log($pointerBase, 2) / 8 : 0;
$this->pointerTestHack = $pointerTestHack;
$this->switchByteOrder = $this->isPlatformLittleEndian();
@@ -118,6 +108,9 @@ class Decoder return $this->decodeByType($type, $offset, $size);
}
+ /**
+ * @param int<0, max> $size
+ */
private function decodeByType(int $type, int $offset, int $size): array
{
switch ($type) {
@@ -195,7 +188,13 @@ class Decoder {
// This assumes IEEE 754 doubles, but most (all?) modern platforms
// use them.
- [, $double] = unpack('E', $bytes);
+ $rc = unpack('E', $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack a double value from the given bytes.'
+ );
+ }
+ [, $double] = $rc;
return $double;
}
@@ -204,7 +203,13 @@ class Decoder {
// This assumes IEEE 754 floats, but most (all?) modern platforms
// use them.
- [, $float] = unpack('G', $bytes);
+ $rc = unpack('G', $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack a float value from the given bytes.'
+ );
+ }
+ [, $float] = $rc;
return $float;
}
@@ -231,7 +236,13 @@ class Decoder );
}
- [, $int] = unpack('l', $this->maybeSwitchByteOrder($bytes));
+ $rc = unpack('l', $this->maybeSwitchByteOrder($bytes));
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack a 32bit integer value from the given bytes.'
+ );
+ }
+ [, $int] = $rc;
return $int;
}
@@ -254,19 +265,31 @@ class Decoder $pointerSize = (($ctrlByte >> 3) & 0x3) + 1;
$buffer = Util::read($this->fileStream, $offset, $pointerSize);
- $offset = $offset + $pointerSize;
+ $offset += $pointerSize;
switch ($pointerSize) {
case 1:
$packed = \chr($ctrlByte & 0x7) . $buffer;
- [, $pointer] = unpack('n', $packed);
+ $rc = unpack('n', $packed);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned short value from the given bytes (pointerSize is 1).'
+ );
+ }
+ [, $pointer] = $rc;
$pointer += $this->pointerBase;
break;
case 2:
$packed = "\x00" . \chr($ctrlByte & 0x7) . $buffer;
- [, $pointer] = unpack('N', $packed);
+ $rc = unpack('N', $packed);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned long value from the given bytes (pointerSize is 2).'
+ );
+ }
+ [, $pointer] = $rc;
$pointer += $this->pointerBase + 2048;
break;
@@ -276,7 +299,13 @@ class Decoder // It is safe to use 'N' here, even on 32 bit machines as the
// first bit is 0.
- [, $pointer] = unpack('N', $packed);
+ $rc = unpack('N', $packed);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned long value from the given bytes (pointerSize is 3).'
+ );
+ }
+ [, $pointer] = $rc;
$pointer += $this->pointerBase + 526336;
break;
@@ -291,7 +320,7 @@ class Decoder if (\PHP_INT_MAX - $pointerBase >= $pointerOffset) {
$pointer = $pointerOffset + $pointerBase;
} else {
- throw new RuntimeException(
+ throw new \RuntimeException(
'The database offset is too large to be represented on your platform.'
);
}
@@ -314,37 +343,44 @@ class Decoder return 0;
}
- $integer = 0;
-
- // PHP integers are signed. _MM_MAX_INT_BYTES is the number of
+ // PHP integers are signed. PHP_INT_SIZE - 1 is the number of
// complete bytes that can be converted to an integer. However,
// we can convert another byte if the leading bit is zero.
- $useRealInts = $byteLength <= _MM_MAX_INT_BYTES
- || ($byteLength === _MM_MAX_INT_BYTES + 1 && (\ord($bytes[0]) & 0x80) === 0);
+ $useRealInts = $byteLength <= \PHP_INT_SIZE - 1
+ || ($byteLength === \PHP_INT_SIZE && (\ord($bytes[0]) & 0x80) === 0);
+
+ if ($useRealInts) {
+ $integer = 0;
+ for ($i = 0; $i < $byteLength; ++$i) {
+ $part = \ord($bytes[$i]);
+ $integer = ($integer << 8) + $part;
+ }
+ return $integer;
+ }
+
+ // We only use gmp or bcmath if the final value is too big
+ $integerAsString = '0';
for ($i = 0; $i < $byteLength; ++$i) {
$part = \ord($bytes[$i]);
- // We only use gmp or bcmath if the final value is too big
- if ($useRealInts) {
- $integer = ($integer << 8) + $part;
- } elseif (\extension_loaded('gmp')) {
- $integer = gmp_strval(gmp_add(gmp_mul((string) $integer, '256'), $part));
+ if (\extension_loaded('gmp')) {
+ $integerAsString = gmp_strval(gmp_add(gmp_mul($integerAsString, '256'), $part));
} elseif (\extension_loaded('bcmath')) {
- $integer = bcadd(bcmul((string) $integer, '256'), (string) $part);
+ $integerAsString = bcadd(bcmul($integerAsString, '256'), (string) $part);
} else {
- throw new RuntimeException(
+ throw new \RuntimeException(
'The gmp or bcmath extension must be installed to read this database.'
);
}
}
- return $integer;
+ return $integerAsString;
}
private function sizeFromCtrlByte(int $ctrlByte, int $offset): array
{
- $size = $ctrlByte & 0x1f;
+ $size = $ctrlByte & 0x1F;
if ($size < 29) {
return [$size, $offset];
@@ -356,10 +392,22 @@ class Decoder if ($size === 29) {
$size = 29 + \ord($bytes);
} elseif ($size === 30) {
- [, $adjust] = unpack('n', $bytes);
+ $rc = unpack('n', $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned short value from the given bytes.'
+ );
+ }
+ [, $adjust] = $rc;
$size = 285 + $adjust;
} else {
- [, $adjust] = unpack('N', "\x00" . $bytes);
+ $rc = unpack('N', "\x00" . $bytes);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned long value from the given bytes.'
+ );
+ }
+ [, $adjust] = $rc;
$size = $adjust + 65821;
}
@@ -375,7 +423,13 @@ class Decoder {
$testint = 0x00FF;
$packed = pack('S', $testint);
+ $rc = unpack('v', $packed);
+ if ($rc === false) {
+ throw new InvalidDatabaseException(
+ 'Could not unpack an unsigned short value from the given bytes.'
+ );
+ }
- return $testint === current(unpack('v', $packed));
+ return $testint === current($rc);
}
}
diff --git a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php index 543fde4..028e63f 100644 --- a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php +++ b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/InvalidDatabaseException.php @@ -1,12 +1,11 @@ <?php
-namespace MaxMind\Db\Reader;
+declare(strict_types=1);
-use Exception;
+namespace MaxMind\Db\Reader;
/**
* This class should be thrown when unexpected data is found in the database.
*/
-class InvalidDatabaseException extends Exception
-{
-}
+// phpcs:disable
+class InvalidDatabaseException extends \Exception {}
diff --git a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Metadata.php b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Metadata.php index 94a5592..3c9be87 100644 --- a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Metadata.php +++ b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Metadata.php @@ -1,71 +1,108 @@ <?php
+declare(strict_types=1);
+
namespace MaxMind\Db\Reader;
/**
* This class provides the metadata for the MaxMind DB file.
- *
- * @property int $nodeCount This is an unsigned 32-bit
- * integer indicating the number of
- * nodes in the search tree.
- * @property int $recordSize This is an unsigned 16-bit
- * integer. It indicates the number
- * of bits in a record in the search
- * tree. Note that each node
- * consists of two records.
- * @property int $ipVersion This is an unsigned 16-bit
- * integer which is always 4 or 6.
- * It indicates whether the database
- * contains IPv4 or IPv6 address
- * data.
- * @property string $databaseType This is a string that indicates
- * the structure of each data record
- * associated with an IP address.
- * The actual definition of these
- * structures is left up to the
- * database creator.
- * @property array $languages An array of strings, each of
- * which is a language code. A given
- * record may contain data items
- * that have been localized to some
- * or all of these languages. This
- * may be undefined.
- * @property int $binaryFormatMajorVersion This is an unsigned 16-bit
- * integer indicating the major
- * version number for the database's
- * binary format.
- * @property int $binaryFormatMinorVersion This is an unsigned 16-bit
- * integer indicating the minor
- * version number for the database's
- * binary format.
- * @property int $buildEpoch This is an unsigned 64-bit
- * integer that contains the
- * database build timestamp as a
- * Unix epoch value.
- * @property array $description This key will always point to a
- * map (associative array). The keys
- * of that map will be language
- * codes, and the values will be a
- * description in that language as a
- * UTF-8 string. May be undefined
- * for some databases.
*/
class Metadata
{
- private $binaryFormatMajorVersion;
- private $binaryFormatMinorVersion;
- private $buildEpoch;
- private $databaseType;
- private $description;
- private $ipVersion;
- private $languages;
- private $nodeByteSize;
- private $nodeCount;
- private $recordSize;
- private $searchTreeSize;
+ /**
+ * This is an unsigned 16-bit integer indicating the major version number
+ * for the database's binary format.
+ *
+ * @var int
+ */
+ public $binaryFormatMajorVersion;
+
+ /**
+ * This is an unsigned 16-bit integer indicating the minor version number
+ * for the database's binary format.
+ *
+ * @var int
+ */
+ public $binaryFormatMinorVersion;
+
+ /**
+ * This is an unsigned 64-bit integer that contains the database build
+ * timestamp as a Unix epoch value.
+ *
+ * @var int
+ */
+ public $buildEpoch;
+
+ /**
+ * This is a string that indicates the structure of each data record
+ * associated with an IP address. The actual definition of these
+ * structures is left up to the database creator.
+ *
+ * @var string
+ */
+ public $databaseType;
+
+ /**
+ * This key will always point to a map (associative array). The keys of
+ * that map will be language codes, and the values will be a description
+ * in that language as a UTF-8 string. May be undefined for some
+ * databases.
+ *
+ * @var array
+ */
+ public $description;
+
+ /**
+ * This is an unsigned 16-bit integer which is always 4 or 6. It indicates
+ * whether the database contains IPv4 or IPv6 address data.
+ *
+ * @var int
+ */
+ public $ipVersion;
+
+ /**
+ * An array of strings, each of which is a language code. A given record
+ * may contain data items that have been localized to some or all of
+ * these languages. This may be undefined.
+ *
+ * @var array
+ */
+ public $languages;
+
+ /**
+ * @var int
+ */
+ public $nodeByteSize;
- public function __construct($metadata)
+ /**
+ * This is an unsigned 32-bit integer indicating the number of nodes in
+ * the search tree.
+ *
+ * @var int
+ */
+ public $nodeCount;
+
+ /**
+ * This is an unsigned 16-bit integer. It indicates the number of bits in a
+ * record in the search tree. Note that each node consists of two records.
+ *
+ * @var int
+ */
+ public $recordSize;
+
+ /**
+ * @var int
+ */
+ public $searchTreeSize;
+
+ public function __construct(array $metadata)
{
+ if (\func_num_args() !== 1) {
+ throw new \ArgumentCountError(
+ sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())
+ );
+ }
+
$this->binaryFormatMajorVersion =
$metadata['binary_format_major_version'];
$this->binaryFormatMinorVersion =
@@ -80,9 +117,4 @@ class Metadata $this->nodeByteSize = $this->recordSize / 4;
$this->searchTreeSize = $this->nodeCount * $this->nodeByteSize;
}
-
- public function __get($var)
- {
- return $this->$var;
- }
}
diff --git a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Util.php b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Util.php index 149a5c4..b8c461e 100644 --- a/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Util.php +++ b/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Util.php @@ -1,10 +1,16 @@ <?php
+declare(strict_types=1);
+
namespace MaxMind\Db\Reader;
class Util
{
- public static function read($stream, $offset, $numberOfBytes)
+ /**
+ * @param resource $stream
+ * @param int<0, max> $numberOfBytes
+ */
+ public static function read($stream, int $offset, int $numberOfBytes): string
{
if ($numberOfBytes === 0) {
return '';
@@ -15,10 +21,11 @@ class Util // We check that the number of bytes read is equal to the number
// asked for. We use ftell as getting the length of $value is
// much slower.
- if (ftell($stream) - $offset === $numberOfBytes) {
+ if ($value !== false && ftell($stream) - $offset === $numberOfBytes) {
return $value;
}
}
+
throw new InvalidDatabaseException(
'The MaxMind DB file contains bad data'
);
|