Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SETUP/tests/unittests/ZipMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions pinc/misc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
}
Expand Down