Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-592

Property name corrupted when unserializing 64-bit integer on 32-bit platform

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.1.3
    • 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.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: