]> granicus.if.org Git - php/commitdiff
Fix bug #69441 (Buffer Overflow when parsing tar/zip/phar in phar_set_inode)
authorStanislav Malyshev <stas@php.net>
Tue, 14 Apr 2015 07:03:50 +0000 (00:03 -0700)
committerStanislav Malyshev <stas@php.net>
Tue, 14 Apr 2015 07:03:50 +0000 (00:03 -0700)
ext/phar/phar_internal.h
ext/phar/tests/bug69441.phar [new file with mode: 0644]
ext/phar/tests/bug69441.phpt [new file with mode: 0644]

index fcfc86457d623350b93e88ab2438a07093bdde86..84282d2a8fe8f3a7da67fa00d9f5dba48f4d8124 100644 (file)
@@ -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 (file)
index 0000000..80956dc
Binary files /dev/null and b/ext/phar/tests/bug69441.phar differ
diff --git a/ext/phar/tests/bug69441.phpt b/ext/phar/tests/bug69441.phpt
new file mode 100644 (file)
index 0000000..ed461cf
--- /dev/null
@@ -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