Skip to content

Commit

Permalink
Fix #79877: getimagesize function silently truncates after a null byte
Browse files Browse the repository at this point in the history
We have to check for NUL bytes if `getimagesize()` has been called.
  • Loading branch information
cmb69 authored and smalyshev committed Aug 3, 2020
1 parent 9c3171f commit 4d2560d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,11 @@ static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) {
Z_PARAM_ZVAL(info)
ZEND_PARSE_PARAMETERS_END();

if (mode == FROM_PATH && CHECK_NULL_PATH(input, input_len)) {
php_error_docref(NULL, E_WARNING, "Invalid path");
return;
}

if (argc == 2) {
info = zend_try_array_init(info);
if (!info) {
Expand Down
9 changes: 9 additions & 0 deletions ext/standard/tests/image/bug79877.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Bug #79877 (getimagesize function silently truncates after a null byte)
--FILE--
<?php
var_dump(getimagesize("/tmp/a.png\0xx"));
?>
--EXPECTF--
Warning: getimagesize(): Invalid path in %s on line %d
NULL

0 comments on commit 4d2560d

Please sign in to comment.