summaryrefslogtreecommitdiffstats
path: root/php-bug77950.patch
blob: c075368708a30bfb5bae59e1e8dad2b5fd97d909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Without test as binary patch not supported




From 8c12f5a635fb4fc5f485bc4f884aea5c7b37f6b0 Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Mon, 29 Apr 2019 23:38:12 -0700
Subject: [PATCH] Fix bug #77950 - Heap-buffer-overflow in _estrndup via
 exif_process_IFD_TAG

I do not completely understand what is going on there, but I am pretty
sure dir_entry <= offset_base if not a normal situation, so we better not
to rely on such dir_entry.

(cherry picked from commit f80ad18afae2230c2c1802c7d829100af646874e)
---
 NEWS                         |  12 ++++++++++--
 ext/exif/exif.c              |   2 +-
 ext/exif/tests/bug77950.phpt |  12 ++++++++++++
 ext/exif/tests/bug77950.tiff | Bin 0 -> 1267 bytes
 4 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 ext/exif/tests/bug77950.phpt
 create mode 100644 ext/exif/tests/bug77950.tiff

diff --git a/NEWS b/NEWS
index a49afe2411..f26a3ad10e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,19 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
+Backported from 7.1.29
+
+- EXIF
+  . Fixed bug #77950 (Heap-buffer-overflow in _estrndup via exif_process_IFD_TAG). 
+    (CVE-2019-11036) (Stas)
+
 Backported from 7.1.28
 
 - EXIF:
-  . Fixed bug #77753 (Heap-buffer-overflow in php_ifd_get32s). (Stas)
-  . Fixed bug #77831 (Heap-buffer-overflow in exif_iif_add_value). (Stas)
+  . Fixed bug #77753 (Heap-buffer-overflow in php_ifd_get32s). (CVE-2019-11034)
+    (Stas)
+  . Fixed bug #77831 (Heap-buffer-overflow in exif_iif_add_value). 
+	(CVE-2019-11035) (Stas)
 
 - SQLite3:
   . Added sqlite3.defensive INI directive. (BohwaZ)
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index 0e490abd1b..a9df95d554 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -2890,7 +2890,7 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
             offset_base is ImageInfo->file.list[sn].data-dir_offset
             dir_entry - offset_base is dir_offset+2+i*12
         */
-		if (byte_count > IFDlength || offset_val > IFDlength-byte_count || value_ptr < dir_entry || offset_val < (size_t)(dir_entry-offset_base)) {
+		if (byte_count > IFDlength || offset_val > IFDlength-byte_count || value_ptr < dir_entry || offset_val < (size_t)(dir_entry-offset_base) || dir_entry <= offset_base) {
 			/* It is important to check for IMAGE_FILETYPE_TIFF
 			 * JPEG does not use absolute pointers instead its pointers are
 			 * relative to the start of the TIFF header in APP1 section. */