[php-src] PHP-8.6: Add test for Phar::buildFromIterator() with a negative getMTime() (#24779)

From: Date: Mon, 02 Nov 2026 15:37:56 +0000
Subject: [php-src] PHP-8.6: Add test for Phar::buildFromIterator() with a negative getMTime() (#24779)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143219@lists.php.net to get a copy of this message
Author: Marc Bennewitz (marc-mabe) Committer: GitHub (web-flow) Pusher: arnaud-lb Date: 2026-11-02T16:37:52+01:00 Commit: https://github.com/php/php-src/commit/eee28563404c2fe8cd3d4ccd3eaf2e59e69cb16d Raw diff: https://github.com/php/php-src/commit/eee28563404c2fe8cd3d4ccd3eaf2e59e69cb16d.diff Add test for Phar::buildFromIterator() with a negative getMTime() (#24779) The fix of ZEND_LONG_UINT_OVFL() on 32-bit platforms also makes Phar::buildFromIterator() reject a negative timestamp there. Changed paths: A ext/phar/tests/buildFromIterator_user_overrides/getMTime_negative.phpt M NEWS Diff: diff --git a/NEWS b/NEWS index 42912edae904..49e7f68744e0 100644 --- a/NEWS +++ b/NEWS @@ -184,6 +184,8 @@ PHP NEWS mounted entries). (Lazizbek Ergashev) . Fixed bug GH-24531 (Crash when modifying a zip-based phar whose file was renamed). (Ilia Alshanetsky) + . Fixed Phar::buildFromIterator() accepting a negative getMTime() on 32bit + platforms. (Marc Bennewitz) - Reflection: . Fixed bug GH-21768 (Assertion failure in ReflectionProperty::isReadable() diff --git a/ext/phar/tests/buildFromIterator_user_overrides/getMTime_negative.phpt b/ext/phar/tests/buildFromIterator_user_overrides/getMTime_negative.phpt new file mode 100644 index 000000000000..315705781647 --- /dev/null +++ b/ext/phar/tests/buildFromIterator_user_overrides/getMTime_negative.phpt @@ -0,0 +1,53 @@ +--TEST-- +buildFromIterator with user overrides - negative getMTime() +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php + +class MySplFileInfo extends SplFileInfo { + public function getMTime(): int|false { + echo "[MTime]\n"; + return -1; + } +} + +class MyIterator extends RecursiveDirectoryIterator { + public function current(): SplFileInfo { + return new MySplFileInfo(parent::current()->getPathname()); + } +} + +$workdir = __DIR__.'/getMTime_negative'; +mkdir($workdir . '/content', recursive: true); +file_put_contents($workdir . '/content/hello.txt', "Hello world."); + +try { + $phar = new \Phar($workdir . "/test.phar"); + $phar->startBuffering(); + $phar->buildFromIterator( + new RecursiveIteratorIterator( + new MyIterator($workdir . '/content', FilesystemIterator::SKIP_DOTS) + ), + $workdir + ); + $phar->stopBuffering(); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--CLEAN-- +<?php +$workdir = __DIR__.'/getMTime_negative'; +@unlink($workdir . '/content/hello.txt'); +@unlink($workdir . '/test.phar'); +@rmdir($workdir . '/content'); +@rmdir($workdir); +?> +--EXPECTF-- +[MTime] +BadMethodCallException: Entry content%chello.txt cannot be created: timestamp is limited to 32-bit

« previous php.cvs (#143219) next »