Skip to content

Commit 3fdde65

Browse files
committed
Fix #76409: heap use after free in _php_stream_free
We must not close the stream in exif_read_from_impl(), since it is the responsibility of the (caller's) caller to do so, if it actually opened the stream. We simplify the reproduce script, which is actually about supplying a path to a directory (opposed to a regular file), and use `.` instead of `/` to also make it work on Windows.
1 parent e029019 commit 3fdde65

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.2.8
44

5+
- EXIF:
6+
. Fixed bug #76409 (heap use after free in _php_stream_free). (cmb)
7+
58
07 Jun 2018, PHP 7.2.7
69

710
- Core:

ext/exif/exif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4324,7 +4324,7 @@ static int exif_read_from_impl(image_info_type *ImageInfo, php_stream *stream, i
43244324
zend_string *base;
43254325
if ((st.st_mode & S_IFMT) != S_IFREG) {
43264326
exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Not a file");
4327-
php_stream_close(ImageInfo->infile);
4327+
ImageInfo->infile = NULL;
43284328
return FALSE;
43294329
}
43304330

ext/exif/tests/bug76409.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #76409 (heap use after free in _php_stream_free)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('exif')) die('skip exif extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
exif_read_data('.');
10+
?>
11+
===DONE===
12+
--EXPECTF--
13+
Warning: exif_read_data(): Not a file in %s on line %d
14+
===DONE===

0 commit comments

Comments
 (0)