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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
From f59b67ae50064560d7bfcdb0d6a8ab284179053c Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Tue, 14 Apr 2015 00:03:50 -0700
Subject: [PATCH] Fix bug #69441 (Buffer Overflow when parsing tar/zip/phar in
phar_set_inode)
---
ext/phar/phar_internal.h | 9 ++++++---
ext/phar/tests/bug69441.phar | Bin 0 -> 5780 bytes
ext/phar/tests/bug69441.phpt | 21 +++++++++++++++++++++
3 files changed, 27 insertions(+), 3 deletions(-)
create mode 100644 ext/phar/tests/bug69441.phar
create mode 100644 ext/phar/tests/bug69441.phpt
diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h
index fcfc864..84282d2 100644
--- a/ext/phar/phar_internal.h
+++ b/ext/phar/phar_internal.h
@@ -618,10 +618,13 @@ static inline void phar_set_inode(phar_entry_info *entry TSRMLS_DC) /* {{{ */
{
char tmp[MAXPATHLEN];
int tmp_len;
+ size_t len;
- tmp_len = entry->filename_len + entry->phar->fname_len;
- memcpy(tmp, entry->phar->fname, entry->phar->fname_len);
- memcpy(tmp + entry->phar->fname_len, entry->filename, entry->filename_len);
+ tmp_len = MIN(MAXPATHLEN, entry->filename_len + entry->phar->fname_len);
+ len = MIN(entry->phar->fname_len, tmp_len);
+ memcpy(tmp, entry->phar->fname, len);
+ len = MIN(tmp_len - len, entry->filename_len);
+ memcpy(tmp + entry->phar->fname_len, entry->filename, len);
entry->inode = (unsigned short)zend_get_hash_value(tmp, tmp_len);
}
/* }}} */
diff --git a/ext/phar/tests/bug69441.phar b/ext/phar/tests/bug69441.phar
new file mode 100644
index 0000000000000000000000000000000000000000..80956dce7cb4fd78117f415166c3c46f62f9f79d
GIT binary patch
literal 5780
zcmWIWW@cdk1DpItw?}h!tuzMmK$wp~h(WI)Be6)oxTG`z$STMy<zoofc5K<k2+_g7
zU}FyyR!B|G$X8Gg4s~{R4GxYE4heNqRJT@$kN0r&35j?1_YLs$aShVYv{taU<K+rK
zv9S2a%lX_u(?FO5XkkfeaS3*-3V^Z*@P&clIn;5P>3NAIrA4WFNtt;J3<2J(Y#?PU
zK)4&|&S02ZLtKMH;*H{65=#;hPGCq-d?RLEVJHLC0m8xvKO-9p^7wzDn~orZA%F=;
zi2!l6FW(yrv59k63Lg-g5jOGi$0`3-1$Z-pq`?3^P#FYZG9VhnaU2DsAut*OLp=nX
zkN_xaGcqx=u(Gjpyx+I>9*FNe3WyE?P<V}k(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7
Sfzc2c4S~@R7!85p9RdJiP@V$-
literal 0
HcmV?d00001
diff --git a/ext/phar/tests/bug69441.phpt b/ext/phar/tests/bug69441.phpt
new file mode 100644
index 0000000..ed461cf
--- /dev/null
+++ b/ext/phar/tests/bug69441.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar: bug #69441: Buffer Overflow when parsing tar/zip/phar in phar_set_inode
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/bug69441.phar';
+try {
+$r = new Phar($fname, 0);
+} catch(UnexpectedValueException $e) {
+ echo $e;
+}
+?>
+
+==DONE==
+--EXPECTF--
+exception 'UnexpectedValueException' with message 'phar error: corrupted central directory entry, no magic signature in zip-based phar "%s/bug69441.phar"' in %s/bug69441.php:%d
+Stack trace:
+#0 %s/bug69441.php(%d): Phar->__construct('%s', 0)
+#1 {main}
+==DONE==
\ No newline at end of file
--
2.1.4
|