|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-08-24 22:05 UTC] mattacosta at gmail dot com
Description: ------------ Multiple adjacent underscores after a leading 0 in a hex or bin number cause a fatal error. https://3v4l.org/jUR51 Test script: --------------- 0x0__F; // or 0b0__1; Expected result: ---------------- Parse error: syntax error, unexpected '__F' (T_STRING) Actual result: -------------- Fatal error: Out of memory (allocated 2097152) (tried to allocate 18446744073709551615 bytes) in /in/jUR51 on line 3 mmap() failed: [22] Invalid argument mmap() failed: [22] Invalid argument Process exited with code 255. PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
It seems that multiple consecutive numeric separators aren't the only problem. If I use any invalid character after 0x0_ or 0b0_ I get the following fatal error: Fatal error: Possible integer overflow in memory allocation (1 * 18446744073709551615 + 1). Here's my initial attempt at a fix. I'm not sure if it's the right approach or not, but it does produce a nicer error message! Zend/zend_language_scanner.l | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 2e21ee7952..901ae1085a 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1776,8 +1776,16 @@ NEWLINE ("\r"|"\n"|"\r\n") /* Skip any leading 0s */ while (*bin == '0' || *bin == '_') { + if (len < 1) { + zend_throw_exception(zend_ce_parse_error, "Invalid numeric literal", 0); + if (PARSER_MODE()) { + RETURN_TOKEN(T_ERROR); + } + RETURN_TOKEN_WITH_VAL(T_LNUMBER); + } else { + --len; + } ++bin; - --len; } contains_underscores = (memchr(bin, '_', len) != NULL); @@ -1893,8 +1901,16 @@ NEWLINE ("\r"|"\n"|"\r\n") /* Skip any leading 0s */ while (*hex == '0' || *hex == '_') { + if (len < 1) { + zend_throw_exception(zend_ce_parse_error, "Invalid numeric literal", 0); + if (PARSER_MODE()) { + RETURN_TOKEN(T_ERROR); + } + RETURN_TOKEN_WITH_VAL(T_LNUMBER); + } else { + --len; + } ++hex; - --len; } contains_underscores = (memchr(hex, '_', len) != NULL);