Skip to content

Regression: strcspn("",) with NUL in haystack returns full length on PROFILE=8.2 — Zend stops at NUL (ext/standard/string.c) #27716

Description

@PurHur

Category

bug · php-src-strict · PHP_COMPILER_PROFILE=8.2 · PHP 8.4 UPGRADING leak · pillar 4

Problem

PHP 8.4 changed strcspn() so an empty $characters returns the full string length even when the haystack contains a NUL byte (previously it stopped at the first NUL). Under PHP_COMPILER_PROFILE=8.2, VM/JIT still apply the 8.4 semantics, so they diverge from Zend 8.2. Verified 2026-08-05 vs host Zend 8.2.32.

Repro Zend 8.2 (PROFILE n/a) VM/JIT PROFILE=8.2 VM PROFILE=8.4 (control)
strcspn("ab\0c", "") 2 (stops at NUL) 4 4 (correct for 8.4)
strcspn("abc", "") 3 3 3

php-src reference

PHP implementation target

  • ext/standard / string strcspn PHP port + shared JIT helper — profile-gate NUL/empty-mask behavior
  • Reuse existing profile helpers (CompilerVersion::languageProfileVersion()); no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc '
cat > /tmp/strcspn_nul.php <<'"'"'PHP'"'"'
<?php
echo strcspn("ab\0c", ""), "\n";
echo strcspn("abc", ""), "\n";
PHP
echo ZEND:; php /tmp/strcspn_nul.php
echo VM82:; PHP_COMPILER_PROFILE=8.2 php bin/vm.php /tmp/strcspn_nul.php
echo VM84:; PHP_COMPILER_PROFILE=8.4 php bin/vm.php /tmp/strcspn_nul.php
'

Done when

  • Under PHP_COMPILER_PROFILE=8.2, strcspn("ab\0c", "") prints 2 matching Zend 8.2 (VM + JIT)
  • Under PHP_COMPILER_PROFILE=8.4 (or default 8.4.0-dev), same call prints 4 (php-src 8.4)
  • Compliance .phpt guards both profiles; php-src-strict; no php-compiler-strict shortcut

Gate context (2026-08-05)

  • bootstrap-inventory --check → OK 7009/7009
  • bootstrap-selfhost-link → OK (gen-0 sidecar emit fallback)
  • release-readiness --json → user_release_ready: yes (north-star5-fast ok)

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 Aug 5, 2026
  2. PurHur commented on Aug 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — batch (issues #27165, #27716, #27827)

    Queued after #27165. PROFILE-gated strcspn empty-characters + NUL haystack parity vs Zend 8.2 / 8.4.

  3. PurHur commented on Aug 8, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib Advanced — starting #27716 (batch #27165/#27716/#27827)

    #27165 merged via #28951. Implementing PROFILE-gated strcspn empty-characters + NUL haystack parity (Zend 8.2 stops at NUL; 8.4 returns full length).

  4. PurHur commented on Aug 8, 2026

    @PurHur
    OwnerAuthor

    Merged #28952

    Verification: PHP_COMPILER_PROFILE=8.2 → strcspn("ab\0c","") prints 2 (VM+JIT); PROFILE=8.4 / unset → 4; existing strcspn("a\0b","") default still 3. StrspnRuntimeShrinkTest OK.

    Next in batch: #27827 highlight HTML wire.

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