Skip to content

Stdlib: parse_str() nested bracket keys — VM Refcount abort regression (#6013 follow-up) #6521

Closed

Description

@PurHur

Category

stdlib · php-src-strict | runtime

Problem

parse_str() with nested bracket notation (b[c]=2&b[d][]=3&b[d][]=4) aborts the VM with:

Refcount is > 1, but was asserted to be 1

instead of building the nested array Zend returns. #6013 closed the JIT/AOT/php-in-PHP micro-runtime path; VM VmParseStr::mergeInto() is still broken for nested keys + list append.

This blocks query-string parsing in web/runtime code (#5965, #5330).

php-src reference

Repro (verified 2026-06-06)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro-maintainer/parity_parse_str_brackets_regression.php
php bin/vm.php test/compliance/cases/stdlib/parse_str_brackets.phpt
php -r "\$o=[]; parse_str(\"a=1&b[c]=2&b[d][]=3&b[d][]=4\",\$o); var_export(\$o);"
'
Runtime Result
Zend array('a'=>1,'b'=>array('c'=>2,'d'=>array(3,4)))
VM Refcount abort ❌
Expected PHPT 1:2:3:4 output

Scope (this repo) — PHP-in-PHP first

Path Role
VM fix ext/standard/VmParseStr.php — mergeInto() refcount when nesting arrays + appending list keys
Handler ext/standard/parse_str.php — keep host \parse_str() import or pure PHP parser aligned with VM
JIT/AOT lib/JIT/Builtin/StringParseStr.php, StringParseStrJit.php — match VM after fix (#6308 phase 2)
C Do not reintroduce runtime/phpc_parse_str.c (removed #6013)

php-src-strict

  • Match Zend nested structure and scalar/list typing exactly
  • Enum case variable names → TypeError (separate guard family; do not regress while fixing merge)

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/compliance/cases/stdlib/parse_str_brackets.phpt
vendor/bin/phpunit --filter parse_str_brackets
'

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 6, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #7558.

    Fix: VmParseStr::ensureArrayChild() now calls separateArrayForWrite() on the bucket zval before returning a child HashTable for in-place mergeInto() — HashTable::add() had bumped refcount via copyFrom(), causing the nested bracket + [] append path to abort.

    Verification:
    ```bash
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro-maintainer/parse_str_brackets.php
    vendor/bin/phpunit --filter parse_str_brackets
    '
    ```
    Repro output matches Zend nested structure; PHPUnit parse_str_brackets green (VM + JIT).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions