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

Dereference array zvals when reading "fieldPaths" type map option

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.20.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • PHP Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      test script :

      <?php
      
      function foo(array &$value): void {}
      $typeMap = ['fieldPaths' => []];
      foo($typeMap['fieldPaths']);
      MongoDB\BSON\Document::fromPHP([])->toPHP($typeMap);
       

      Unexpected error:

      PHP Fatal error:  Uncaught MongoDB\Driver\Exception\InvalidArgumentException: The 'fieldPaths' element is not an array in typemap.php:6
      Stack trace:
      #0 typemap.php(25): MongoDB\BSON\Document->toPHP(Array)
      #1 {main}
        thrown in typemap.php on line 6
      

      https://github.com/mongodb/mongo-php-driver/blob/5518255188be716bbab0b3f2aef7a862ccaf0c87/src/phongo_bson.c#L1381-L1386 

      If we remove the call to the function, there is no error.

      PHPC version: 5518255188be716bbab0b3f2aef7a862ccaf0c87

      php --ri mongodb
      
      MongoDB support => enabled
      MongoDB extension version => 1.21.0dev
      MongoDB extension stability => devel
      libbson bundled version => 1.28.0
      libmongoc bundled version => 1.28.0
      libmongoc SSL => enabled
      libmongoc SSL library => OpenSSL
      libmongoc crypto => enabled
      libmongoc crypto library => libcrypto
      libmongoc crypto system profile => disabled
      libmongoc SASL => enabled
      libmongoc SRV => enabled
      libmongoc compression => enabled
      libmongoc compression snappy => disabled
      libmongoc compression zlib => enabled
      libmongoc compression zstd => enabled
      libmongocrypt bundled version => 1.11.0
      libmongocrypt crypto => enabled
      libmongocrypt crypto library => libcrypto
      crypt_shared library version => unknownDirective => Local Value => Master Value
      mongodb.debug => no value => no value
      
      php -v
      PHP 8.3.8 (cli) (built: Jun  4 2024 14:53:17) (NTS)
      Copyright (c) The PHP Group
      Zend Engine v4.3.8, Copyright (c) Zend Technologies
          with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
          with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
      

      Context:

      I tracked this issue when upgrading to PHPUnit 10.

      The test FunctionTest::testApplyTypeMapToDocument #2 fails

      https://github.com/mongodb/mongo-php-library/blob/0960e1c25a00206d47937a6509d805b675e7ac38/tests/FunctionsTest.php#L85

      The bug appears on phpunit/phpunit b
      color: Color value is invalid
      etween 10.5.3 and 10.5.4

      With the commit https://github.com/sebastianbergmann/phpunit/commit/5d049893b805733369a72dab5b92556a1f665eb9
      At some point, it calls sebastian/recursion-context 5.0.0, the method https://github.com/sebastianbergmann/recursion-context/blob/5.0/src/Context.php#L69

      This method call creates this error.

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: