Skip to content

A string[] local reassigned from array_merge()/array_slice() results is read back with the wrong element repr when unrelated bare-array calls of the same functions exist (SIGSEGV). #384

Closed

Description

@blacktrs

Summary

A string[] local reassigned from array_merge()/array_slice() results is read back with the wrong element repr when unrelated bare-array calls of the same functions exist (SIGSEGV).

Repro

<?php
/** @return string[] */
function pieces(string $g): array
{
    return explode('|', $g);
}

function isSpace(string $p): bool
{
    return $p[0] !== '/';
}

function hasR(string $p): bool
{
    return $p === 'z';
}

/** @param string[] $pieces */
function put(array $pieces): string
{
    return \implode('', $pieces);
}

function fix(string $ga, string $gb, string $ws): string
{
    $a = pieces($ga);
    $b = pieces($gb);
    $m = \count($a);
    if (!hasR($a[$m - 1])) {
        $target = 2;
        if ($target >= 0) {
            $a = \array_merge($a, \array_slice($b, 0, $target + 1));
            $b = \array_slice($b, $target + 1);
            $m = \count($a);
        }
    }
    $last = -1;
    for ($x = $m - 1; $x >= 0; $x--) {
        $last = $x;
        break;
    }
    if ($last >= 0 && isSpace($a[$last])) {
        $a[$last] = $ws;
    } else {
        $a[] = 'q';
    }
    return put($a);
}

function runArgs(array $argv): int
{
    return \count(\array_slice($argv, 1));
}

function withProgramName(array $args): int
{
    return \count(\array_merge(['x'], $args));
}

echo runArgs(\array_merge(['x'], ['help'])), "\n";
echo fix(' ', " |// c|\n", "\n"), "\n";

Expected (php)

1
  // c

Actual (manticore 515a500a, Darwin arm64)


[exit code 139 — SIGSEGV]

Tracking

Known-bug repro: tests/aot/repro/crash/array_merge_slice_local_string_vec_mono_mismatch.php — bash tests/aot/xfail.sh -k array_merge_slice_local_string_vec_mono_mismatch 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
    crash
    on Oct 23, 2026
  2. blacktrs commented on Oct 23, 2026

    @blacktrs
    ContributorAuthor

    Found via manticore-fmt tests/main.php (segfault in BracesPosition::fixBrace, isWs($a[$last])). Same class as #376: dump-mir of this repro shows local $a stored from pieces() as vec[string] and from array_merge(...) as vec[cell] (the un-specialised variadic prelude body; its sibling array_merge$mono$p0_vec_vec_str serves another call site), while later loads of $a are typed vec[string]. The array_slice$mono$p0_vec_str result (vec[string]) only becomes concrete after Monomorphize, so the array_merge pack key is not concrete before it and the whole-store scan (InferScans::scanWholeStoreElemClasses, pre-Mono only) sees no conflict. Needs the post-Mono re-bind/convert described in #376.

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