|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-02-21 14:44 UTC] r3d dot w0rm at yahoo dot com
Description: ------------ PHP str_repeat() Function Integer Overflow AUTHOR : Sina Yazdanmehr(R3d.W0rm) Discovered by : Sina Yazdanmehr (R3d.W0rm) Our Site : http://IrCrash.com Our Forums : http://ircrash.com/persian/ My Official WebSite : http://R3dW0rm.ir IRCRASH Team Members : Khashayar Fereidani - R3d.w0rm (Sina Yazdanmehr) Reproduce code: --------------- <?php //www.IrCrash.com //By : R3d.W0rm $str1 = str_repeat('0x0x0x0x',999999999); $str2 = str_repeat($str,1); ?> Expected result: ---------------- Fatal error: Possible integer overflow in memory allocation (8 * 999999999 + 1) in F:\Program Files\EasyPHP-5.3.1\www\over.php on line 4 Fatal error: Possible integer overflow in memory allocation (8 * 999999999 + 1) in /var/www/html/over.php on line 4 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 23:00:01 2025 UTC |
PHP says you do not have enough memory to do this. The string generated would be 8GiB in size. Also, this can be simplified as: Reproduce code: --------------- <?php str_repeat('0x0x0x0x',999999999); Actual result: --------------- Fatal error: Possible integer overflow in memory allocation (8 * 999999999 + 1) in crash.php on line 2The problem was not reproducible because you were using 64-bit php which uses 64-bit signed integers. Try this: <?php $str1 = str_repeat('0x0x0x0x', 18446744073709551615); echo "all good so far...\n"; $str2 = str_repeat('0x0x0x0x', 2305843009213693952); ?> 18446744073709551615 is 2^64 - 1, which is -1 in two's compliment. 2305843009213693952 is 2^61 Output: all good so far... PHP Fatal error: Possible integer overflow in memory allocation (8 * 2305843009213693952 + 1) in /tmp/test.php on line 4 Expected output: PHP Fatal error: Possible integer overflow in memory allocation (8 * 18446744073709551615 + 1) in /tmp/test.php on line 2 all good so far... PHP Fatal error: Possible integer overflow in memory allocation (8 * 2305843009213693952 + 1) in /tmp/test.php on line 4