-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 1.1.2
-
Component/s: None
-
None
It seems that I lied when I proclaimed that reading an Int64 from the db is fine. It turns out that it comes back as a string and is liable to have its property name mangled.
With the following test document:
{ "_id" : ObjectId("569d015eb26caf586174252a"), "TestObj" : { "Slots" : NumberLong(-429496729552) } }if I fetch it in php and then var_dump the result, I get:
object(stdClass)#13 (2) { ["_id"]=> object(MongoDB\BSON\ObjectID)#11 (1) { ["oid"]=> string(24) "569d015eb26caf586174252a" } ["TestObj"]=> object(stdClass)#12 (1) { ["Slots0"]=> string(13) "-429496729552" } }Notice that "Slots" became "Slots0". The appended characters seem to depend on the combination of property name and integer value. With the right values you can end up with invalid UTF8.
This appears to be caused by the ADD_ASSOC_INT64() compatibility macro, which is called from php_phongo_bson_visit_int64(). That macro relies on ADD_ASSOC_STRINGL(), which in turn uses ZEND_STRL() and calculates the property string's length using sizeof(str)-1. This makes it suitable only for string literals and not the const char * passed through libbson's visitor function. Currently, the pointer size is being used to derive the string length.
- is related to
-
PHPC-544 Consult SIZEOF_ZEND_LONG for 64-bit integer support
- Closed