Skip to content

Commit f4b0b32

Browse files
committed
Raise E_WARNING on PHP related errors
If Zip operations fails due to PHP error conditions before libzip even has been called, there is no meaningful indication what failed; the functions just return false, and the Zip status indicated that no error did occur. Therefore we raise `E_WARNING` in these cases. Closes GH-6356.
1 parent ed64d1b commit f4b0b32

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

ext/zip/php_zip.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,13 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
288288
}
289289

290290
if (!expand_filepath(filename, resolved_path)) {
291+
php_error_docref(NULL, E_WARNING, "No such file or directory");
291292
return -1;
292293
}
293294

294295
php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag);
295296
if (Z_TYPE(exists_flag) == IS_FALSE) {
297+
php_error_docref(NULL, E_WARNING, "No such file or directory");
296298
return -1;
297299
}
298300

@@ -1163,6 +1165,7 @@ PHP_FUNCTION(zip_open)
11631165
}
11641166

11651167
if(!expand_filepath(ZSTR_VAL(filename), resolved_path)) {
1168+
php_error_docref(NULL, E_WARNING, "No such file or directory");
11661169
RETURN_FALSE;
11671170
}
11681171

@@ -1444,6 +1447,7 @@ PHP_METHOD(ZipArchive, open)
14441447
}
14451448

14461449
if (!(resolved_path = expand_filepath(ZSTR_VAL(filename), NULL))) {
1450+
php_error_docref(NULL, E_WARNING, "No such file or directory");
14471451
RETURN_FALSE;
14481452
}
14491453

ext/zip/tests/bug64342_0.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ DONE
3838
?>
3939
--EXPECTF--
4040
%s.txt
41+
42+
Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
4143
add failed
4244
close ok
4345
DONE

ext/zip/tests/bug64342_1-mb.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
3737
}
3838
@unlink($file);
3939
?>
40-
--EXPECT--
40+
--EXPECTF--
41+
Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
4142
failed
4243
OK

ext/zip/tests/bug64342_1.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
3737
}
3838
@unlink($file);
3939
?>
40-
--EXPECT--
40+
--EXPECTF--
41+
Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
4142
failed
4243
OK

0 commit comments

Comments
 (0)