Skip to content

Commit 259af93

Browse files
committed
Promote warnings in exif
The only thing that can promoted are the path-related checked. Everything else is input dependent and error-suppressing these functions is both the typical and the recommended usage.
1 parent 382cb2e commit 259af93

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

ext/exif/exif.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -4536,9 +4536,13 @@ PHP_FUNCTION(exif_read_data)
45364536
}
45374537

45384538
if (!Z_STRLEN_P(stream)) {
4539-
exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_WARNING, "Filename cannot be empty");
4539+
zend_argument_value_error(1, "cannot be empty");
4540+
RETURN_THROWS();
4541+
}
45404542

4541-
RETURN_FALSE;
4543+
if (CHECK_NULL_PATH(Z_STRVAL_P(stream), Z_STRLEN_P(stream))) {
4544+
zend_argument_type_error(1, "cannot contain any null-bytes");
4545+
RETURN_THROWS();
45424546
}
45434547

45444548
ret = exif_read_from_file(&ImageInfo, Z_STRVAL_P(stream), read_thumbnail, read_all);
@@ -4709,9 +4713,13 @@ PHP_FUNCTION(exif_thumbnail)
47094713
}
47104714

47114715
if (!Z_STRLEN_P(stream)) {
4712-
exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_WARNING, "Filename cannot be empty");
4716+
zend_argument_value_error(1, "cannot be empty");
4717+
RETURN_THROWS();
4718+
}
47134719

4714-
RETURN_FALSE;
4720+
if (CHECK_NULL_PATH(Z_STRVAL_P(stream), Z_STRLEN_P(stream))) {
4721+
zend_argument_type_error(1, "cannot contain any null-bytes");
4722+
RETURN_THROWS();
47154723
}
47164724

47174725
ret = exif_read_from_file(&ImageInfo, Z_STRVAL_P(stream), 1, 0);

ext/exif/tests/filename_empty.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Passing empty filename to exif_read_data() and exif_thumnail()
3+
--FILE--
4+
<?php
5+
6+
try {
7+
exif_read_data("");
8+
} catch (ValueError $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
try {
13+
exif_thumbnail("");
14+
} catch (ValueError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
exif_read_data("foo\0bar");
20+
} catch (TypeError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
try {
25+
exif_thumbnail("foo\0bar");
26+
} catch (TypeError $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
?>
31+
--EXPECT--
32+
exif_read_data(): Argument #1 ($filename) cannot be empty
33+
exif_thumbnail(): Argument #1 ($filename) cannot be empty
34+
exif_read_data(): Argument #1 ($filename) cannot contain any null-bytes
35+
exif_thumbnail(): Argument #1 ($filename) cannot contain any null-bytes

0 commit comments

Comments
 (0)