summaryrefslogtreecommitdiff
path: root/ext/zlib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zlib/tests')
-rw-r--r--ext/zlib/tests/bug.tarbin0 -> 4720640 bytes
-rw-r--r--ext/zlib/tests/bug_40189.phpt25
-rw-r--r--ext/zlib/tests/bug_40189_2.phpt14
-rw-r--r--ext/zlib/tests/zlib_filter_inflate2.phpt41
4 files changed, 80 insertions, 0 deletions
diff --git a/ext/zlib/tests/bug.tar b/ext/zlib/tests/bug.tar
new file mode 100644
index 000000000..77fd77832
--- /dev/null
+++ b/ext/zlib/tests/bug.tar
Binary files differ
diff --git a/ext/zlib/tests/bug_40189.phpt b/ext/zlib/tests/bug_40189.phpt
new file mode 100644
index 000000000..07e5191a9
--- /dev/null
+++ b/ext/zlib/tests/bug_40189.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #40189 (endless loop in zlib.inflate stream filter)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+// this string is an excerpt of a phar archive that caused an infinite loop
+$a = "\x3\x0\x85\x46\x2f\x7c\xc2\xaa\x69\x2b\x6d\xe5\xdb\xfe\xe4\x21\x8f\x0\x97\x21\x1d\x2\x0\x0\x0\x47\x42\x4d\x42";
+var_dump(base64_encode($a));
+$gp = fopen(dirname(__FILE__) . '/test.other', 'wb');
+$fp = fopen('data://text/plain;base64,AwCFRi98wqppK23l2/7kIY8AlyEdAgAAAEdCTUI=', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+var_dump(stream_copy_to_stream($fp, $gp, 5));
+fclose($fp);
+fclose($gp);
+var_dump(file_get_contents(dirname(__FILE__) . '/test.other'));
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/test.other');
+?>
+--EXPECT--
+string(40) "AwCFRi98wqppK23l2/7kIY8AlyEdAgAAAEdCTUI="
+int(0)
+string(0) ""
diff --git a/ext/zlib/tests/bug_40189_2.phpt b/ext/zlib/tests/bug_40189_2.phpt
new file mode 100644
index 000000000..13a19dbd9
--- /dev/null
+++ b/ext/zlib/tests/bug_40189_2.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #40189 (test for truncated deflate, also part of erroneous fix for #40189)
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php
+$a = fopen(dirname(__FILE__). '/bug.tar', 'rb');
+stream_filter_append($a, 'zlib.deflate', STREAM_FILTER_READ, array('window' => 15+16));
+$b = fread($a, 4716032);
+var_dump(strlen($b));
+// when broken, this outputs "int(686904)"
+?>
+--EXPECT--
+int(1676116) \ No newline at end of file
diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt
new file mode 100644
index 000000000..028e743ee
--- /dev/null
+++ b/ext/zlib/tests/zlib_filter_inflate2.phpt
@@ -0,0 +1,41 @@
+--TEST--
+zlib.inflate of gzip-encoded stream
+--SKIPIF--
+<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--FILE--
+<?php /* $Id: zlib_filter_inflate2.phpt,v 1.1.2.3 2008/04/08 08:45:04 jani Exp $ */
+
+$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
+fwrite($a, "This is quite the thing ain't it\n");
+fclose($a);
+
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
+echo fread($fp, 2000);
+fclose($fp);
+echo "1\n";
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+// zlib format
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+16));
+echo "2\n";
+echo fread($fp, 2000);
+fclose($fp);
+// auto-detect
+$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
+stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+32));
+echo "3\n";
+echo fread($fp, 2000);
+fclose($fp);
+
+?>
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/test.txt.gz');
+?>
+--EXPECT--
+1
+2
+This is quite the thing ain't it
+3
+This is quite the thing ain't it \ No newline at end of file