Skip to content

by-ref foreach: growing $v then reading/unsetting the element through the container is a use-after-free #17

Closed

Description

@blacktrs

Summary

by-ref foreach: growing $v then reading/unsetting the element through the container is a use-after-free.

Repro

<?php
$a = ['x', 'y'];
foreach ($a as $k => &$v) {
    $v .= str_repeat('z', 100);
    echo strlen($a[$k]), "\n";
    unset($a[$k]);
}
unset($v);
echo count($a), "\n";

Expected (php 8.5)

101
101
0

Actual (manticore 10affa68, macOS arm64)

1
1
0

Tracking

Known-bug repro: tests/aot/repro/crash/foreach_byref_grow_then_read.php — bash tests/aot/xfail.sh -k foreach_byref_grow_then_read reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

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

    bugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions