Skip to content

Commit e8932d4

Browse files
authored
Merge pull request #126 from maxmind/greg/32-bit-build
Test 32-bit build and fix bcmath issue. Closes #124
2 parents d11b3a7 + db7b83a commit e8932d4

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@ on: [push, pull_request]
55
jobs:
66
run:
77
runs-on: ${{ matrix.operating-system }}
8+
container: shivammathur/node:latest-${{ matrix.arch }}
89
strategy:
910
matrix:
11+
arch: ["amd64", "i386"]
1012
operating-system: [ubuntu-latest]
1113
php-versions: ['7.2', '7.3', '7.4', '8.0']
12-
name: "PHP ${{ matrix.php-versions }} test on ${{ matrix.operating-system }}"
14+
php-extensions: ['bcmath', 'gmp']
15+
name: "PHP ${{ matrix.php-versions }} (with ${{ matrix.php-extensions }}) test on ${{ matrix.operating-system }}/${{ matrix.arch }}"
1316
steps:
14-
- name: Setup PHP
15-
uses: shivammathur/setup-php@v2
16-
with:
17-
php-version: ${{ matrix.php-versions }}
18-
tools: composer, phpize
19-
20-
- name: Setup problem matchers for PHPUnit
21-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
17+
- name: Install PHP
18+
run: |
19+
spc -U
20+
spc --php-version "${{ matrix.php-versions }}" \
21+
--extensions "mbstring, intl, ${{ matrix.php-extensions }}" \
22+
--ini-values "post_max_size=256M, max_execution_time=180" \
23+
--coverage "xdebug" \
24+
--tools "composer,phpize"
2225
2326
- name: Checkout
24-
uses: actions/checkout@v2
27+
# We use v1 due to https://github.com/actions/checkout/issues/334
28+
uses: actions/checkout@v1
2529
with:
2630
submodules: true
2731

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
1.10.1
5+
-------------------
6+
7+
* Fix a `TypeError` exception in the pure PHP reader when using large
8+
databases on 32-bit PHP builds with the `bcmath` extension. Reported
9+
by dodo1708. GitHub #124.
10+
411
1.10.0 (2021-02-09)
512
-------------------
613

src/MaxMind/Db/Reader/Decoder.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,13 @@ private function decodePointer(int $ctrlByte, int $offset): array
286286
// machines
287287
$pointerOffset = $this->decodeUint($buffer, $pointerSize);
288288

289-
$byteLength = $pointerSize + $this->pointerBaseByteSize;
290-
291-
if ($byteLength <= _MM_MAX_INT_BYTES) {
292-
$pointer = $pointerOffset + $this->pointerBase;
293-
} elseif (\extension_loaded('gmp')) {
294-
$pointer = gmp_strval(gmp_add($pointerOffset, $this->pointerBase));
295-
} elseif (\extension_loaded('bcmath')) {
296-
$pointer = bcadd($pointerOffset, (string) $this->pointerBase);
289+
$pointerBase = $this->pointerBase;
290+
291+
if (\PHP_INT_MAX - $pointerBase >= $pointerOffset) {
292+
$pointer = $pointerOffset + $pointerBase;
297293
} else {
298294
throw new RuntimeException(
299-
'The gmp or bcmath extension must be installed to read this database.'
295+
'The database offset is too large to be represented on your platform.'
300296
);
301297
}
302298

tests/MaxMind/Db/Test/Reader/DecoderTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class DecoderTest extends TestCase
159159
*/
160160
private function pointers(): array
161161
{
162-
return [
162+
$v = [
163163
['expected' => 0, 'input' => [0x20, 0x0]],
164164
['expected' => 5, 'input' => [0x20, 0x5]],
165165
['expected' => 10, 'input' => [0x20, 0xa]],
@@ -168,9 +168,14 @@ private function pointers(): array
168168
['expected' => 524283, 'input' => [0x2f, 0xf7, 0xfb]],
169169
['expected' => 526335, 'input' => [0x2f, 0xff, 0xff]],
170170
['expected' => 134217726, 'input' => [0x37, 0xf7, 0xf7, 0xfe]],
171-
['expected' => \PHP_INT_MAX < 4294967295 ? '2147483647' : 2147483647, 'input' => [0x38, 0x7f, 0xff, 0xff, 0xff]],
172-
['expected' => \PHP_INT_MAX < 4294967295 ? '4294967295' : 4294967295, 'input' => [0x38, 0xff, 0xff, 0xff, 0xff]],
171+
['expected' => 2147483647, 'input' => [0x38, 0x7f, 0xff, 0xff, 0xff]],
173172
];
173+
174+
if (\PHP_INT_MAX > 4294967295) {
175+
array_push($v, ['expected' => 4294967295, 'input' => [0x38, 0xff, 0xff, 0xff, 0xff]]);
176+
}
177+
178+
return $v;
174179
}
175180

176181
/**

0 commit comments

Comments
 (0)