|
| 1 | +--TEST-- |
| 2 | +Passing a too long string to ChildNode or ParentNode methods causes an exception |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--INI-- |
| 6 | +memory_limit=-1 |
| 7 | +--SKIPIF-- |
| 8 | +<?php |
| 9 | +if (PHP_INT_SIZE !== 8) die('skip Only for 64-bit'); |
| 10 | +if (getenv('SKIP_SLOW_TESTS')) die('skip slow test'); |
| 11 | +// Copied from file_get_contents_file_put_contents_5gb.phpt |
| 12 | +function get_system_memory(): int|float|false |
| 13 | +{ |
| 14 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
| 15 | + // Windows-based memory check |
| 16 | + @exec('wmic OS get FreePhysicalMemory', $output); |
| 17 | + if (isset($output[1])) { |
| 18 | + return ((int)trim($output[1])) * 1024; |
| 19 | + } |
| 20 | + } else { |
| 21 | + // Unix/Linux-based memory check |
| 22 | + $memInfo = @file_get_contents("/proc/meminfo"); |
| 23 | + if ($memInfo) { |
| 24 | + preg_match('/MemFree:\s+(\d+) kB/', $memInfo, $matches); |
| 25 | + return $matches[1] * 1024; // Convert to bytes |
| 26 | + } |
| 27 | + } |
| 28 | + return false; |
| 29 | +} |
| 30 | +if (get_system_memory() < 4 * 1024 * 1024 * 1024) { |
| 31 | + die('skip Reason: Insufficient RAM (less than 4GB)'); |
| 32 | +} |
| 33 | +?> |
| 34 | +--FILE-- |
| 35 | +<?php |
| 36 | +$dom = new DOMDocument; |
| 37 | +$element = $dom->appendChild($dom->createElement('root')); |
| 38 | +$str = str_repeat('X', 2**31 + 10); |
| 39 | +try { |
| 40 | + $element->append('x', $str); |
| 41 | +} catch (ValueError $e) { |
| 42 | + echo $e->getMessage(), "\n"; |
| 43 | +} |
| 44 | +try { |
| 45 | + $element->prepend('x', $str); |
| 46 | +} catch (ValueError $e) { |
| 47 | + echo $e->getMessage(), "\n"; |
| 48 | +} |
| 49 | +try { |
| 50 | + $element->after('x', $str); |
| 51 | +} catch (ValueError $e) { |
| 52 | + echo $e->getMessage(), "\n"; |
| 53 | +} |
| 54 | +try { |
| 55 | + $element->before('x', $str); |
| 56 | +} catch (ValueError $e) { |
| 57 | + echo $e->getMessage(), "\n"; |
| 58 | +} |
| 59 | +try { |
| 60 | + $element->replaceWith('x', $str); |
| 61 | +} catch (ValueError $e) { |
| 62 | + echo $e->getMessage(), "\n"; |
| 63 | +} |
| 64 | +try { |
| 65 | + $element->replaceChildren('x', $str); |
| 66 | +} catch (ValueError $e) { |
| 67 | + echo $e->getMessage(), "\n"; |
| 68 | +} |
| 69 | +var_dump($dom->childNodes->count()); |
| 70 | +var_dump($element->childNodes->count()); |
| 71 | +?> |
| 72 | +--EXPECT-- |
| 73 | +DOMElement::append(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 74 | +DOMElement::prepend(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 75 | +DOMElement::after(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 76 | +DOMElement::before(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 77 | +DOMElement::replaceWith(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 78 | +DOMElement::replaceChildren(): Argument #2 must be less than or equal to 2147483647 bytes long |
| 79 | +int(1) |
| 80 | +int(0) |
0 commit comments