Bug #77519 [NEW]: Regression in updating PHP arrays by functions provided by extensions.

From: Date: Fri, 25 Jan 2019 14:35:42 +0000
Subject: Bug #77519 [NEW]: Regression in updating PHP arrays by functions provided by extensions.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219200@lists.php.net to get a copy of this message
From: chris dot e dot munt at gmail dot com Operating system: Ubuntu 18.04; CentOS 7.3; Window PHP version: 7.3.1 Package: Arrays related Bug Type: Bug Bug description:Regression in updating PHP arrays by functions provided by extensions. Description: ------------ There appears to be a regression (between PHP 7.2.x and 7.3.x) involving arrays passed by reference between PHP script and extensions. I have not been able to get a back-trace but include a very simple example that demonstrates the problem, together with the results obtained for 7.2.12 (expected) and the crash that occurs when the same code is run through 7.3.1. The flow is that an array is initialized in PHP script using 'array()', then passed as an input argument to an extension function which attempts to add records to that array. This worked fine for all PHP versions prior to 7.3. The extension code is included below. Interestingly, if the initialization of the array is coded as 'array(0)' then the script runs, albeit with an extra '0' record in the data. It would appear that something isn't being initialized properly within the PHP 7.3 engine when the 'array()' construct is processed. Extension C Code ================ #include "php.h" #include "ext/standard/info.h" #include "SAPI.h" #include "php_ini.h" #define PHP_ATEST_EXTNAME "atest" #define PHP_ATEST_VERSION "1.0.0" static PHP_FUNCTION(atest_function); static const zend_function_entry atest_functions[] = { PHP_FE(atest_function, NULL) {NULL, NULL, NULL} }; zend_module_entry atest_module_entry = { STANDARD_MODULE_HEADER, PHP_ATEST_EXTNAME, atest_functions, NULL, NULL, NULL, NULL, NULL, PHP_ATEST_VERSION, STANDARD_MODULE_PROPERTIES }; ZEND_GET_MODULE(atest) ZEND_FUNCTION(atest_function) { int argument_count; zval parameter_array_a[32] = {0}, *parameter_array = parameter_array_a; zend_printf("\r\natest_function() PHP Version: %d.%d.%d\r\n", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION); argument_count = ZEND_NUM_ARGS(); if (argument_count < 1) WRONG_PARAM_COUNT; if(zend_get_parameters_array_ex(argument_count, parameter_array) != SUCCESS) WRONG_PARAM_COUNT; add_assoc_string(&(parameter_array_a[0]), "1", "value 1"); add_assoc_string(&(parameter_array_a[0]), "2", "value 2"); add_assoc_string(&(parameter_array_a[0]), "3", "value 3"); RETVAL_NULL(); } Test script: --------------- <html> <head><title>Array test</title></head> <?php $arr = array(); atest_function($arr); print("\r\n<p>Array passed by reference ...<p>\r\n"); foreach($arr as $k1=>$v1) { echo "\r\n<br>",$k1," = ",$v1; } ?> </html> Expected result: ---------------- Result for v7.2.12 ================== <html> <head><title>Array test</title></head> atest_function() PHP Version: 7.2.12 <p>Array passed by reference ...<p> <br>1 = value 1 <br>2 = value 2 <br>3 = value 3</html> Result for v7.3.1 ================= <html> <head><title>Array test</title></head> atest_function() PHP Version: 7.3.1 Segmentation fault (core dumped) -- Edit bug report at https://bugs.php.net/bug.php?id=77519&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77519&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77519&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77519&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77519&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77519&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77519&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77519&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77519&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77519&r=support Expected behavior: https://bugs.php.net/fix.php?id=77519&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77519&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77519&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77519&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77519&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77519&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77519&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77519&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77519&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77519&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77519&r=mysqlcfg

« previous php.bugs (#219200) next »