1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 17:38:14 +02:00

new test for truncated file comment, fix memleak found by test

This commit is contained in:
Greg Beaver
2008-04-19 05:39:42 +00:00
parent 4e98585ff7
commit bd3ddde29f
7 changed files with 22 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
--TEST--
Phar: corrupted zip (truncated file comment)
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
--FILE--
<?php
try {
new PharData(dirname(__FILE__) . '/files/filecomment.zip');
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
?>
===DONE===
--EXPECTF--
phar error: corrupt zip archive, zip file comment truncated in zip-based phar "%sfilecomment.zip"
===DONE===
@@ -6,4 +6,5 @@ $a->addFile('hi2', null, 'hii2');
$a->writeZip(dirname(__FILE__) . '/count1.zip', 'count1');
$a->writeZip(dirname(__FILE__) . '/count2.zip', 'count2');
$a->writeZip(dirname(__FILE__) . '/nozipend.zip', 'none');
$a->writeZip(dirname(__FILE__) . '/filecomment.zip', 'comment');
?>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -212,9 +212,13 @@ foundit:
if (locator.comment_len) {
metadata = (char *) emalloc(PHAR_GET_16(locator.comment_len));
if (locator.comment_len != php_stream_read(fp, metadata, PHAR_GET_16(locator.comment_len))) {
if (error) {
spprintf(error, 4096, "phar error: corrupt zip archive, zip file comment truncated in zip-based phar \"%s\"", fname);
}
php_stream_close(fp);
efree(mydata->fname);
efree(mydata);
efree(metadata);
return FAILURE;
}
if (phar_parse_metadata(&metadata, &mydata->metadata, PHAR_GET_16(locator.comment_len) TSRMLS_CC) == FAILURE) {