Skip to content

An array row is shared without copy-on-write after array_map #26

Closed

Description

@blacktrs

Summary

An array row is shared without copy-on-write after array_map.

Already fixed on branch ownership-2; closes when that branch lands on main. Tracking only.

Repro

<?php
$s = [['s' => 0, 'e' => 'q']];
$t = array_map(fn($i) => $i, $s);
$s[0]['e'] = 'r';
var_dump($t[0]['e']);

Expected (php 8.5)

string(1) "q"

Actual (manticore 10affa68, macOS arm64)

string(1) "r"

Tracking

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

Activity

  1. added
    bug
    wrong-answer
    on Oct 5, 2026
  2. blacktrs commented on Oct 5, 2026

    @blacktrs
    ContributorAuthor

    Severity note: this is not only a wrong answer. The row array_map hands back is shared without a retain, so it is released twice at scope exit — a double free. glibc and macOS absorb it; musl faults: tests/aot/cases/array_identity_raw_vs_cell_rows died with SIGSEGV on both Alpine CI rows at 09cb49fb.

    libgmalloc stack on macOS: __mir_array_release_cell ← __mir_array_release_ownel_cell ← main.

    That case was rewritten in 3dc6ed40 to build its rows with array_merge($i, []) so it no longer depends on this bug; the repro here still covers it.

  3. added
    crash
    on Oct 5, 2026
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

    bugcrashwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions