summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/phar/tests/zip/largezip.phpt29
-rw-r--r--ext/phar/zip.c4
2 files changed, 33 insertions, 0 deletions
diff --git a/ext/phar/tests/zip/largezip.phpt b/ext/phar/tests/zip/largezip.phpt
new file mode 100644
index 0000000000..93cbaca256
--- /dev/null
+++ b/ext/phar/tests/zip/largezip.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Phar: large zip file (zip edge cases)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip");?>
+--INI--
+phar.require_hash=0
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.zip.php';
+$pname = 'phar://' . $fname;
+$pname2 = 'phar://' . $fname2;
+
+$p = new Phar($fname);
+$p['big'] = str_repeat(str_repeat('hi', 100), 1000);
+$p['big2'] = str_repeat(str_repeat('hi', 100), 1000);
+
+copy($fname, $fname2);
+$p2 = new Phar($fname2);
+var_dump(strlen($p2['big']));
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?>
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.zip.php'); ?>
+--EXPECT--
+int(100000)
+===DONE===
diff --git a/ext/phar/zip.c b/ext/phar/zip.c
index c77273dafe..9e0ddce9e7 100644
--- a/ext/phar/zip.c
+++ b/ext/phar/zip.c
@@ -168,6 +168,9 @@ int phar_open_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, i
php_stream_close(fp);
return FAILURE;
}
+ if (*p == 'P' && !memcmp(p + 1, "K\5\6", 3)) {
+ goto copybuf;
+ }
while ((p=(char *) memchr(p + 1, 'P', (size_t)(buf - (p+1) + 8192 - 4 + 1))) != NULL) {
if (!memcmp(p + 1, "K\5\6", 3)) {
if (p - buf < sizeof(locator)) {
@@ -178,6 +181,7 @@ int phar_open_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, i
return FAILURE;
}
} else {
+copybuf:
memcpy((void *)&locator, (void *) p, sizeof(locator));
}
goto foundit;