Skip to content

Commit 1c1b8b6

Browse files
committed
Fix bug #71391: NULL Pointer Dereference in phar_tar_setupmetadata()
1 parent 285cd34 commit 1c1b8b6

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

ext/phar/tar.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ static int phar_tar_setupmetadata(void *pDest, void *argument TSRMLS_DC) /* {{{
880880

881881
if (entry->filename_len >= sizeof(".phar/.metadata") && !memcmp(entry->filename, ".phar/.metadata", sizeof(".phar/.metadata")-1)) {
882882
if (entry->filename_len == sizeof(".phar/.metadata.bin")-1 && !memcmp(entry->filename, ".phar/.metadata.bin", sizeof(".phar/.metadata.bin")-1)) {
883+
if (entry->phar->metadata == NULL) {
884+
return ZEND_HASH_APPLY_REMOVE;
885+
}
883886
return phar_tar_setmetadata(entry->phar->metadata, entry, error TSRMLS_CC);
884887
}
885888
/* search for the file this metadata entry references */

ext/phar/tests/bug71391.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Phar: bug #71391: NULL Pointer Dereference in phar_tar_setupmetadata()
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
// duplicate since the tar will change
8+
copy(__DIR__."/bug71391.tar", __DIR__."/bug71391.test.tar");
9+
$p = new PharData(__DIR__."/bug71391.test.tar");
10+
$p->delMetaData();
11+
?>
12+
DONE
13+
--CLEAN--
14+
<?php
15+
unlink(__DIR__."/bug71391.test.tar");
16+
?>
17+
--EXPECT--
18+
DONE

ext/phar/tests/bug71391.tar

3.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)