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

BSON document produces driver segfault

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.0-RC1, 1.4.0
    • Affects Version/s: 1.3.4
    • Component/s: None
    • None

      mongodb/mongo-php-library#449 reported a curious issue where using a specific document in a findOne query resulted in an InvalidArgumentException with the following message:

      Client Error: bad object in message: bson length doesn't match what we found in object with unknown _id

      This error message come from bson_validate.cpp in the server.

      The following script reproduces the error:

      $x = [
          '_______'                             => new MongoDB\BSON\ObjectID('111111111111111111111111'),
          '___________________________________' => new MongoDB\BSON\Regex('_______________________________________________________', 'i'),
      ];
      
      $manager = new MongoDB\Driver\Manager;
      $query = new MongoDB\Driver\Query($x);
      $manager->executeQuery('test.foo', $query);
      

      Aside from the error message, it's odd that this is reported as an InvalidArgumentException instead of a RuntimeException.

      Beyond this, attempting to insert the same document produces a segfault:

      $x = [
          '_______'                             => new MongoDB\BSON\ObjectID('111111111111111111111111'),
          '___________________________________' => new MongoDB\BSON\Regex('_______________________________________________________', 'i'),
      ];
      
      $manager = new MongoDB\Driver\Manager;
      $bulk = new MongoDB\Driver\BulkWrite;
      $bulk->insert($x);
      $manager->executeBulkWrite('test', $bulk);
      

      This appears to be specific to the PHP driver and libmongoc, as the document can be used just fine via the shell:

      > var x = {
      ...     "_______": ObjectId('111111111111111111111111'),
      ...     "___________________________________": RegExp("_______________________________________________________", "i")
      ... }
      > db.foo.insert(x)
      WriteResult({ "nInserted" : 1 })
      > db.foo.findOne(x)
      {
      	"_id" : ObjectId("5a31bad2384dbd1739b73f6d"),
      	"_______" : ObjectId("111111111111111111111111"),
      	"___________________________________" : /_______________________________________________________/i
      }
      

            Assignee:
            derick Derick Rethans
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: