Skip to content

Stdlib: SplFixedArray OOB offsetSet uncaught — Zend catchable RuntimeException (ext/spl/spl_fixedarray.c) #21994

Description

@PurHur

Category

bug · php-src-strict · SplFixedArray exception delivery

Problem

Out-of-range SplFixedArray writes must throw a user-catchable RuntimeException (Index invalid or out of range). Zend's try { $a[5]=1; } catch (Throwable) catches it. The VM prints an Uncaught RuntimeException fatal and never enters the user catch — exception escapes the script try/catch around the dim write.

In-tree throw site: ext/spl/SplFixedArrayBuiltin.php (offsetSet).

Probed 2026-07-22 vs host Zend 8.2.32.

Repro Zend 8.2 VM
$a=new SplFixedArray(3); try{$a[5]=1;}catch(Throwable $e){echo get_class($e);} RuntimeException Uncaught fatal RuntimeException: Index invalid or out of range (catch never runs)

php-src reference

PHP implementation target

  • ext/spl/SplFixedArrayBuiltin.php — ensure throw uses VM exception path (not abort/fatal bypass)
  • lib/VM.php / lib/VM/ArrayAccessDimension.php — dim-write from ArrayAccess must deliver thrown exceptions to active try handlers
  • No new C runtime logic

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/spl_oob.php <<'"'"'PHP'"'"'
<?php
$a = new SplFixedArray(3);
try { $a[5] = 1; echo "no-throw\n"; }
catch (Throwable $e) { echo "caught:", get_class($e), "\n"; }
PHP
php /tmp/spl_oob.php
php bin/vm.php /tmp/spl_oob.php'

Done when

  • VM prints caught:RuntimeException (matches Zend)
  • JIT/AOT agree when in scope
  • Compliance .phpt under test/compliance/cases/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    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 Jul 22, 2026
  2. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #21977, #21994, #22007)

    Working #21977 first (SplMinHeap/SplMaxHeap subclass compare). Then #21994, then #22007. Separate PRs; merge each before the next.

  3. PurHur commented on Jul 22, 2026

    @PurHur
    OwnerAuthor

    Merged in #22011

    Verification

    • VM + JIT: test/repro/splfixedarray_oob_catchable_21994.php → caught:RuntimeException / after
    • ./script/phpunit.sh --filter 'splfixedarray_oob_catchable|…' → OK (6)

    Batch continues with #22007 (ParentIterator + RII).

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 machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions