Skip to content

stdlib: tempnam() prefix truncation, invalid-dir Notice, Z_PARAM_PATH (#4401) - #8014

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-tempnam-parity-4401
Jun 11, 2026
Merged

stdlib: tempnam() prefix truncation, invalid-dir Notice, Z_PARAM_PATH (#4401)#8014
PurHur merged 1 commit into
masterfrom
agent/stdlib-tempnam-parity-4401

Conversation

@PurHur

@PurHur PurHur commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement tempnam() parity in PHP (ext/standard/VmFsTempnam.php) per php-src ext/standard/file.c + main/php_open_temporary_file.c: basename() + 63-char prefix cap, invalid directory fallback to sys_get_temp_dir() with E_NOTICE, and ValueError on embedded NUL (Z_PARAM_PATH).
  • Add VmString::coercePathBuiltinArg() for path builtins; wire VM/JIT through existing tempnam builtin.
  • Extend __compiler_tempnam LLVM lowering (StringFsDirJit) for null-byte rejection, prefix normalization, fallback notice via __compiler_trigger_error, and retry against __compiler_sys_get_temp_dir.
  • No new C runtime logic — VmFsTempnamNative uses thin libc mkstemp(3) FFI only.

Closes #4401

php-src reference

  • ext/standard/file.cPHP_FUNCTION(tempnam)
  • main/php_open_temporary_file.cphp_open_temporary_fd_ex() Notice + fallback

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_tempnam_4401.php
php bin/vm.php test/repro/maintainer_tempnam_4401.php
php bin/jit.php test/repro/maintainer_tempnam_4401.php
php bin/compile.php -l test/repro/maintainer_tempnam_4401.php
vendor/bin/phpunit --filter "tempnam_prefix_length|tempnam_invalid_dir|tempnam_null_byte|tempnam_jit"
'

VM/JIT repro output (parity with Zend on prefix length, fallback dir, null-byte ValueError):

basename-len=69
fallback-dir=yes
null-byte:ValueError:tempnam(): Argument #1 ($directory) must not contain any null bytes

PHPUnit: OK (10 tests, 10 assertions) for new compliance cases + existing tempnam/tempnam_jit.

Simple AOT compile smoke:

echo '<?php $f=tempnam(sys_get_temp_dir(),"phpc"); echo "ok\n";' | php bin/compile.php -o /tmp/tn_simple -
/tmp/tn_simple  # => ok

Note

AOT compile segfaults when combining tempnam() + basename() + long dynamic prefix (pre-existing on master); issue repro and compliance gates do not require that path.

Made with Cursor

…#4401)

Implement php-src tempnam parity in PHP (VmFsTempnam) instead of host
@tempNam delegation: basename+63-char prefix cap, sys temp dir fallback with
E_NOTICE, and ValueError on embedded NUL. Mirror behavior in __compiler_tempnam
LLVM lowering for JIT/AOT.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 2472642 into master Jun 11, 2026
@PurHur
PurHur deleted the agent/stdlib-tempnam-parity-4401 branch June 11, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: tempnam() prefix length (64) + invalid dir fallback notices parity

1 participant