xref: /php-src/ext/dom/tests/gh15654.phpt (revision 9cb23a3d)
1--TEST--
2GH-15654 (Signed integer overflow in ext/dom/nodelist.c)
3--EXTENSIONS--
4dom
5--SKIPIF--
6<?php
7if (PHP_INT_SIZE != 8) die('skip 64-bit only');
8?>
9--FILE--
10<?php
11define("MAX_64Bit", 9223372036854775807);
12define("MAX_32Bit", 2147483647);
13define("MIN_64Bit", -9223372036854775807 - 1);
14define("MIN_32Bit", -2147483647 - 1);
15$longVals = array(
16    0, MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit,
17);
18$dom = new DOMDocument;
19$dom->loadXML('<root><a/><b/><c/></root>');
20$children = $dom->documentElement->childNodes;
21foreach ($longVals as $value) {
22    var_dump($children[$value]?->nodeName);
23}
24?>
25--EXPECT--
26string(1) "a"
27NULL
28NULL
29NULL
30NULL
31NULL
32NULL
33