Bug #75147 [NEW]: add_assoc_zval() may still create integer keys in object HashTables
| From: | jmikola@php.net | Date: | Fri, 01 Sep 2017 20:21:57 +0000 |
| Subject: | Bug #75147 [NEW]: add_assoc_zval() may still create integer keys in object HashTables | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-210907@lists.php.net to get a copy of this message | ||
From: jmikola
Operating system:
PHP version: 7.2.0RC1
Package: Class/Object related
Bug Type: Bug
Bug description:add_assoc_zval() may still create integer keys in object HashTables
Description:
------------
While running the mongodb extension's test suite with PHP 7.2.0RC1, I
noticed several new failures that appear to be related to the BC
incompatible changes in
https://github.com/php/php-src/blob/php-7.2.0RC1/UPGRADING#L28.
Specifically:
> Casting arrays to objects (with (object) or settype()) will now
convert integer keys to string property names.
One of the more concise tests that now fail is:
https://github.com/mongodb/mongo-php-driver/blob/598e8e2845c5de09a3591276bcb6d328be48a697/tests/bson/bson-utcdatetime-001.phpt#L36
In this test, we create a numerically-indexed array that contains a
single zval (a BSON class in this particular case, but that's not
relevant) and convert it to BSON and back to PHP. The interim BSON
representation is a document/object with a "0" string key. When
converting back to PHP, we use add_assoc_zval() with "0" to assign the
converted zval back to the output.
add_assoc_zval() ultimately calls zend_symtable_str_update()
<https://github.com/php/php-src/blob/php-7.2.0RC1/Zend/zend_hash.h#L456>,
which then converts our "0" string key to integer 0 via
_zend_handle_numeric_str_ex(). Effectively, we end up creating an
inaccessible numeric property on the object, which is exactly what the
change in 7.2.0's array->object casting intended to address.
My question is whether add_assoc_zval_ex() should be changed to no
longer convert numeric string keys to integer keys. I'll note that this
decision would likely have to be made in add_assoc_zval_ex() because
zend_symtable_str_update() is only provided the HashTable* and by that
point we have no way of determining if the corresponding zval for that
HashTable is an array or object type.
Alternatively, is it the mongodb extension's responsibility to detect
this case an manually call zend_hash_str_update() instead of relying on
add_assoc_zval()?
--
Edit bug report at https://bugs.php.net/bug.php?id=75147&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75147&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75147&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75147&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75147&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75147&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75147&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75147&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75147&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75147&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75147&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75147&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75147&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75147&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75147&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75147&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75147&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75147&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75147&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75147&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75147&r=mysqlcfg