From 772a798ce77ff0dc7d992a913735f21965ebe9e1 Mon Sep 17 00:00:00 2001 From: Brian Foley Date: Thu, 3 Sep 2026 17:53:58 +0100 Subject: [PATCH] misc.inc: Make validate_zip_file aware of PHP 8.4 ER_TRUNCATED_ZIP ...and update unit test to accept both ER_INCONS & ER_TRUNCATED_ZIP --- SETUP/tests/unittests/ZipMethodsTest.php | 12 ++++++++++-- pinc/misc.inc | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/SETUP/tests/unittests/ZipMethodsTest.php b/SETUP/tests/unittests/ZipMethodsTest.php index ab8da77103..a832998834 100644 --- a/SETUP/tests/unittests/ZipMethodsTest.php +++ b/SETUP/tests/unittests/ZipMethodsTest.php @@ -92,7 +92,11 @@ public function testValidateValidEmptyZipFile(): void public function testValidateCorruptedZipFile(): void { - $this->expectExceptionMessage("ZipArchive::open() returned 'Zip archive inconsistent.'"); + $this->expectExceptionMessageMatches( + "/^ZipArchive::open\\(\\) returned '" . + "(Zip archive inconsistent|Truncated archive)" . + "\\.'$/" + ); validate_zip_file('./data/corrupted.zip'); } @@ -122,7 +126,11 @@ public function testValidateValidEmptyZipFileWithDisabledExtensionCheck(): void public function testValidateCorruptedZipFileWithDisabledExtensionCheck(): void { - $this->expectExceptionMessage("ZipArchive::open() returned 'Zip archive inconsistent.'"); + $this->expectExceptionMessageMatches( + "/^ZipArchive::open\\(\\) returned '" . + "(Zip archive inconsistent|Truncated archive)" . + "\\.'$/" + ); validate_zip_file('./data/corrupted.zip', true); } diff --git a/pinc/misc.inc b/pinc/misc.inc index 7aafec50f4..8e4461f78f 100644 --- a/pinc/misc.inc +++ b/pinc/misc.inc @@ -1118,6 +1118,10 @@ function validate_zip_file(string $file_path, bool $ignore_extension_check = fal ZipArchive::ER_READ => "Read error.", ZipArchive::ER_SEEK => "Seek error.", ]; + // PHP 8.4 and later + if (defined('ZipArchive::ER_TRUNCATED_ZIP')) { + $zip_results[ZipArchive::ER_TRUNCATED_ZIP] = "Truncated archive."; + } $error = $zip_results[$result] ?? "Error code $result"; throw new ZipException("ZipArchive::open() returned '$error'"); }