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
|
From bf58162ddf970f63502837f366930e44d6a992cf Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Sat, 4 Jul 2015 21:01:50 -0700
Subject: [PATCH] Fix bug #69958 - Segfault in Phar::convertToData on invalid
file
---
ext/phar/phar_object.c | 70 ++++++++++++++++++++++---------------------
ext/phar/tests/bug69958.phpt | 14 +++++++++
ext/phar/tests/bug69958.tar | Bin 0 -> 513 bytes
3 files changed, 50 insertions(+), 34 deletions(-)
create mode 100644 ext/phar/tests/bug69958.phpt
create mode 100644 ext/phar/tests/bug69958.tar
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index add1fa0..1184863 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -2419,7 +2419,9 @@ no_copy:
zend_hash_destroy(&(phar->manifest));
zend_hash_destroy(&(phar->mounted_dirs));
zend_hash_destroy(&(phar->virtual_dirs));
- php_stream_close(phar->fp);
+ if (phar->fp) {
+ php_stream_close(phar->fp);
+ }
efree(phar->fname);
efree(phar);
return NULL;
diff --git a/ext/phar/tests/bug69958.phpt b/ext/phar/tests/bug69958.phpt
new file mode 100644
index 0000000..d63b413
--- /dev/null
+++ b/ext/phar/tests/bug69958.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Phar: bug #69958: Segfault in Phar::convertToData on invalid file
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$tarphar = new PharData(__DIR__.'/bug69958.tar');
+$phar = $tarphar->convertToData(Phar::TAR);
+--EXPECTF--
+Fatal error: Uncaught exception 'BadMethodCallException' with message 'phar "%s/bug69958.tar" exists and must be unlinked prior to conversion' in %s/bug69958.php:%d
+Stack trace:
+#0 %s/bug69958.php(%d): PharData->convertToData(%d)
+#1 {main}
+ thrown in %s/bug69958.php on line %d
diff --git a/ext/phar/tests/bug69958.tar b/ext/phar/tests/bug69958.tar
new file mode 100644
index 0000000000000000000000000000000000000000..02275248bd08524f937a67e851f02ee38148e7f0
GIT binary patch
literal 513
NcmZQz7zHCb1ONg700961
literal 0
HcmV?d00001
--
2.1.4
|