Category
stdlib — php-src-strict
Problem
unpack($format, $data, $offset) argument #3 must be int. Passing a backed enum case must TypeError (… must be of type int, E given). VM today coerces the backing scalar (e.g. E::A with backing 0 → offset 0) and proceeds.
php-src reference
Repro
<?php
enum E: int { case A = 0; }
$data = "\x00\x00\x00\x01";
try {
var_export(unpack('i', $data, E::A));
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage() . "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "enum E: int { case A = 0; } try { var_export(unpack(\"i\", \"\\x00\\x00\\x00\\x01\", E::A)); } catch (Throwable \$e) { echo get_class(\$e).\": \".\$e->getMessage(); }"'
# Today: array(1 => …) — WRONG (backing 0 used as offset)
# Target: TypeError: unpack(): Argument #3 ($offset) must be of type int, E given
Scope (this repo)
| Piece |
Path |
| VM builtin |
ext/standard/unpack.php — $offset = VmMath::parseIntBuiltinArg(...) |
| Int guards |
ext/standard/VmMath.php — rejectEnumCaseIntBuiltinArg() / enumCaseEntryForVariable() |
| Engine |
ext/standard/UnpackEngine.php (unchanged once offset typed) |
| JIT |
ext/standard/JitUnpack.php (mirror guard) |
Root cause likely: enum case not detected before parseLongBuiltinArgCore() backing coercion.
Done when
Verify
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter unpack_offset_enum'
Links
#1492 · #6078 · #6213 · #6267 · #5780
Category
stdlib— php-src-strictProblem
unpack($format, $data, $offset)argument #3 must beint. Passing a backed enum case mustTypeError(… must be of type int, E given). VM today coerces the backing scalar (e.g.E::Awith backing0→ offset0) and proceeds.php-src reference
ext/standard/pack.c—php_unpack()Z_PARAM_LONG on$offsetRepro
Scope (this repo)
ext/standard/unpack.php—$offset = VmMath::parseIntBuiltinArg(...)ext/standard/VmMath.php—rejectEnumCaseIntBuiltinArg()/enumCaseEntryForVariable()ext/standard/UnpackEngine.php(unchanged once offset typed)ext/standard/JitUnpack.php(mirror guard)Root cause likely: enum case not detected before
parseLongBuiltinArgCore()backing coercion.Done when
TypeErroron VMunpack('i', $data, 0)unchangedtest/compliance/cases/stdlib/unpack_offset_enum_typeerror.phptgreenVerify
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter unpack_offset_enum'Links
#1492 · #6078 · #6213 · #6267 · #5780