com php-src: Fix bug #69453 - don't try to cut empty string: ext/phar/tar.c ext/phar/tests/bug69453.phpt
| From: | Stanislav Malyshev | Date: | Thu, 30 Apr 2015 05:51:43 +0000 |
| Subject: | com php-src: Fix bug #69453 - don't try to cut empty string: ext/phar/tar.c ext/phar/tests/bug69453.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86710@lists.php.net to get a copy of this message | ||
Commit: c27f012b7a447e59d4a704688971cbfa7dddaa74
Author: Stanislav Malyshev <stas@php.net> Wed, 29 Apr 2015 22:04:20 -0700
Parents: ac2832935435556dc593784cd0087b5e576bbe4d
Branches: PHP-5.4 PHP-5.4.41
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c27f012b7a447e59d4a704688971cbfa7dddaa74
Log:
Fix bug #69453 - don't try to cut empty string
Bugs:
https://bugs.php.net/69453
Changed paths:
M ext/phar/tar.c
A ext/phar/tests/bug69453.phpt
Diff:
diff --git a/ext/phar/tar.c b/ext/phar/tar.c
index ca8eafc..d6d63e6 100644
--- a/ext/phar/tar.c
+++ b/ext/phar/tar.c
@@ -425,7 +425,7 @@ bail:
entry.filename_len = i;
entry.filename = pestrndup(hdr->name, i, myphar->is_persistent);
- if (entry.filename[entry.filename_len - 1] == '/') {
+ if (i > 0 && entry.filename[entry.filename_len - 1] == '/') {
/* some tar programs store directories with trailing slash */
entry..filename[entry.filename_len - 1] = '\0';
entry.filename_len--;
diff --git a/ext/phar/tests/bug69453.phpt b/ext/phar/tests/bug69453..phpt
new file mode 100644
index 0000000..4a2a37f
--- /dev/null
+++ b/ext/phar/tests/bug69453.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Phar: bug #69453: Memory Corruption in phar_parse_tarfile when entry filename starts with null
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/bug69453.tar..phar';
+try {
+$r = new Phar($fname, 0);
+} catch(UnexpectedValueException $e) {
+ echo $e;
+}
+?>
+
+==DONE==
+--EXPECTF--
+exception 'UnexpectedValueException' with message 'phar error:
"%s/bug69453.tar.phar" is a corrupted tar file (checksum mismatch of file
"")' in %s:%d
+Stack trace:
+#0 %s/bug69453.php(%d): Phar->__construct('%s', 0)
+#1 {main}
+==DONE==
\ No newline at end of file