summaryrefslogtreecommitdiffstats
path: root/bug71498.patch
blob: d4977e725c616dd75dd8b9a60c38eb31239cca89 (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
Backported from 5.5 for 5.4 by Remi Collet
binary patch dropped

From a6fdc5bb27b20d889de0cd29318b3968aabb57bd Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Sun, 21 Feb 2016 16:51:05 -0800
Subject: [PATCH] Fix bug #71498: Out-of-Bound Read in phar_parse_zipfile()

---
 ext/phar/tests/bug71488.phpt |   1 +
 ext/phar/tests/bug71498.phpt |  17 +++++++++++++++++
 ext/phar/tests/bug71498.zip  | Bin 0 -> 65677 bytes
 ext/phar/zip.c               |   6 +++---
 4 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 ext/phar/tests/bug71498.phpt
 create mode 100644 ext/phar/tests/bug71498.zip

diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index e4883d3..7f294c2 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -199,7 +199,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias,
 	}
 
 	while ((p=(char *) memchr(p + 1, 'P', (size_t) (size - (p + 1 - buf)))) != NULL) {
-		if (!memcmp(p + 1, "K\5\6", 3)) {
+		if ((p - buf) + sizeof(locator) <= size && !memcmp(p + 1, "K\5\6", 3)) {
 			memcpy((void *)&locator, (void *) p, sizeof(locator));
 			if (PHAR_GET_16(locator.centraldisk) != 0 || PHAR_GET_16(locator.disknumber) != 0) {
 				/* split archives not handled */