php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #71504
Patch patch.txt revision 2016-02-03 09:37 UTC by zawadi at gmail dot com

Patch patch.txt for PHAR related Bug #71504

Patch version 2016-02-03 09:37 UTC

Return to Bug #71504 | Download this patch
Patch Revisions:

Developer: zawadi@gmail.com

diff --git a/ext/phar/tar.c b/ext/phar/tar.c
index 1fcfe52..c4b2c9f 100644
--- a/ext/phar/tar.c
+++ b/ext/phar/tar.c
@@ -500,7 +500,21 @@ bail:
 			entry.link = estrndup(hdr->linkname, linkname_len);
 		}
 		phar_set_inode(&entry TSRMLS_CC);
-		zend_hash_add(&myphar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), (void **) &newentry);
+		
+		if (zend_hash_exists(&myphar->manifest, entry.filename, entry.filename_len)) {
+			zend_hash_update(&myphar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), (void **) &newentry);
+		} else {
+			zend_hash_add(&myphar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), (void **) &newentry);
+		}
+
+		if (newentry == NULL) {
+			if (error) {
+				spprintf(error, 4096, "phar error: tar-based phar \"%s\" cannot be registered because of invalid file entry \"%s\"", fname, entry.filename);
+			}
+			php_stream_close(fp);
+			phar_destroy_phar_data(myphar TSRMLS_CC);
+			return FAILURE;
+		}
 
 		if (entry.is_persistent) {
 			++entry.manifest_pos;
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri May 24 03:01:26 2019 UTC