Skip to content

A string|bool|null parameter reassigned to a string inside if (true === $format) segfaults when later passed to sprintf #185

Closed

Description

@blacktrs

Summary

A string|bool|null parameter reassigned to a string inside if (true === $format) segfaults when later passed to sprintf.

Repro

<?php
final class B
{
    public function getEnv(string $n): string { return strtoupper($n); }
    public function esc(string $v): string { return str_replace('%', '%%', $v); }

    public function resolve(mixed $value, string|bool|null $format = null, ?array &$usedEnvs = null): mixed
    {
        if (true === $format) {
            $format = '%%env(%s)%%';
        }
        if (\is_string($value)) {
            foreach (['foo' => ['env_a'], 'bar' => ['env_b']] as $env => $placeholders) {
                foreach ($placeholders as $placeholder) {
                    if (false !== stripos($value, $placeholder)) {
                        if (true === $format) {
                            $resolved = $this->esc($this->getEnv($env));
                        } else {
                            $resolved = sprintf($format, $env);
                        }
                        $usedEnvs[$env] = $env;
                        $value = str_ireplace($placeholder, $resolved, $value);
                    }
                }
            }
        }
        return $value;
    }
}

$b = new B();
$used = [];
echo $b->resolve('x env_a y', true, $used), "\n";
echo $b->resolve('x env_b y', '[%s]', $used), "\n";
echo $b->resolve('nothing', null), "\n";
echo implode(',', array_keys($used)), "\n";

Expected (php)

x %env(foo)% y
x [bar] y
nothing
foo,bar

Actual (manticore a3d33b63, Darwin arm64)


[exit code 139 — SIGSEGV]

Tracking

Known-bug repro: tests/aot/repro/crash/union_param_reassigned_in_branch_then_sprintf.php — bash tests/aot/xfail.sh -k union_param_reassigned_in_branch_then_sprintf 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 11, 2026
  2. added a commit that references this issue on Oct 14, 2026
    a4951d3
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