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

Recursive bsonSerialize() output may segfault

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 0.5.1
    • Component/s: None

      The following test begins to segfault around 12750 iterations:

      --TEST--
      Test for PHPC-276: BSON\Serializable recursion
      --SKIPIF--
      <?php require __DIR__ . "/../utils/basic-skipif.inc"?>
      --FILE--
      <?php
      require_once __DIR__ . "/../utils/basic.inc";
      
      class MyClass implements BSON\Serializable
      {
          private $recursion;
      
          public function __construct($recursion)
          {
              $this->recursion = $recursion;
          }
      
          public function bsonSerialize()
          {
              return ($this->recursion >= 1)
                ? array(new self($this->recursion - 1))
                : array('end');
          }
      }
      
      $bson = BSON\fromArray(new MyClass(12750));
      echo BSON\toJSON($bson), "\n";
      echo "Encoded BSON:\n";
      hex_dump($bson);
      
      ?>
      ===DONE===
      <?php exit(0); ?>
      --EXPECT--
      ...
      ===DONE===
      

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

              Created:
              Updated: