Skip to content

Convert more zlib warnings to exceptions #12708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ext/standard/tests/filters/filter_errors_zlib_inflate.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Filter errors: zlib.inflate
--FILE--
<?php
require 'filter_errors.inc';
filter_errors_test('zlib.inflate', gzencode('42'));
try {
filter_errors_test('zlib.inflate', gzencode('42'));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
test filtering of buffered data

Notice: stream_filter_append(): zlib: data error in %s on line %d

Warning: stream_filter_append(): Filter failed to process pre-buffered data in %s
test filtering of non buffered data

Notice: stream_get_contents(): zlib: data error in %s on line %d
zlib: data error
41 changes: 23 additions & 18 deletions ext/zlib/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zlib

try {
var_dump(gzcompress("", 1000));
} catch (\ValueError $e) {
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

Expand All @@ -24,23 +24,36 @@ var_dump($data2 = gzcompress($string, 9));

try {
var_dump(gzuncompress("", 1000));
} catch (\ValueError $e) {
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
var_dump(gzuncompress("", -1));
} catch (\ValueError $e) {
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(gzuncompress(""));
var_dump(gzuncompress("", 9));
try {
var_dump(gzuncompress(""));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
var_dump(gzuncompress("", 9));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(gzuncompress($data1));
var_dump(gzuncompress($data2));
$data2[4] = 0;
var_dump(gzuncompress($data2));
try {
var_dump(gzuncompress($data2));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
Expand All @@ -50,22 +63,14 @@ string(%d) "%a"
string(%d) "%a"
string(%d) "%a"
string(%d) "%a"

Warning: gzuncompress(): %s error in %s on line %d
bool(false)
data error
gzuncompress(): Argument #2 ($max_length) must be greater than or equal to 0

Warning: gzuncompress(): %s error in %s on line %d
bool(false)

Warning: gzuncompress(): %s error in %s on line %d
bool(false)
data error
data error
string(94) "Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony"
string(94) "Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony"

Warning: gzuncompress(): %s error in %s on line %d
bool(false)
data error
57 changes: 34 additions & 23 deletions ext/zlib/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zlib

try {
var_dump(gzcompress("", 1000));
} catch (\ValueError $e) {
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

Expand All @@ -23,23 +23,44 @@ Desolation, grief and agony";
var_dump($data1 = gzdeflate($string));
var_dump($data2 = gzdeflate($string, 9));

var_dump(gzinflate(""));
var_dump(gzinflate("asfwe", 1000));
try {
var_dump(gzinflate(""));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
var_dump(gzinflate("asfwe", 1000));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
var_dump(gzinflate("asdf", -1));
} catch (\ValueError $e) {
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

try {
var_dump(gzinflate("asdf"));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(gzinflate("asdf"));
var_dump(gzinflate("asdf", 9));
try {
var_dump(gzinflate("asdf", 9));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

var_dump(gzinflate($data1));
var_dump(gzinflate($data2));
$data2[4] = 0;
var_dump(gzinflate($data2));

try {
var_dump(gzinflate($data2));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
gzcompress(): Argument #2 ($level) must be between -1 and 9
Expand All @@ -48,25 +69,15 @@ string(%d) "%a"
string(%d) "%a"
string(%d) "%a"
string(%d) "%a"

Warning: gzinflate(): data error in %s on line %d
bool(false)

Warning: gzinflate(): data error in %s on line %d
bool(false)
data error
data error
gzinflate(): Argument #2 ($max_length) must be greater than or equal to 0

Warning: gzinflate(): data error in %s on line %d
bool(false)

Warning: gzinflate(): data error in %s on line %d
bool(false)
data error
data error
string(94) "Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony"
string(94) "Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony"

Warning: gzinflate(): data error in %s on line %d
bool(false)
data error
10 changes: 6 additions & 4 deletions ext/zlib/tests/bug61139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Bug #61139 (gzopen leaks when specifying invalid mode)
zlib
--FILE--
<?php

gzopen('someFile', 'c');
?>
try {
gzopen('someFile', 'c');
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
--CLEAN--
<?php
unlink('someFile');
?>
--EXPECTF--
Warning: gzopen(): gzopen failed in %s on line %d
gzopen failed
42 changes: 18 additions & 24 deletions ext/zlib/tests/bug71417.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ function test($case) {
// The gzdecode() function applied to the corrupted compressed data always
// detects the error:
// --> gzdecode(): PHP Fatal error: Uncaught ErrorException: gzdecode(): data error in ...
echo "gzdecode(): ", rawurldecode(gzdecode($compressed)), "\n";
try {
echo "gzdecode(): ", rawurldecode(gzdecode($compressed)), "\n";
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

file_put_contents($fn, $compressed);

$r = fopen($fn, "r");
stream_filter_append($r, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+16));
while (!feof($r)) {
$s = fread($r, 100);
echo "read: "; var_dump($s);
try {
$s = fread($r, 100);
echo "read: "; var_dump($s);
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
}
fclose($r);
unlink($fn);
Expand All @@ -66,25 +74,11 @@ test(4);

?>
--EXPECTF--
gzdecode():
Warning: gzdecode(): data error in %s on line %d


Notice: fread(): zlib: data error in %s on line %d
read: bool(false)
gzdecode():
Warning: gzdecode(): data error in %s on line %d

gzdecode(): data error
zlib: data error
gzdecode(): data error
read: string(32) "The quick brown fox jumps over t"
gzdecode():
Warning: gzdecode(): data error in %s on line %d


Notice: fread(): zlib: data error in %s on line %d
read: bool(false)
gzdecode():
Warning: gzdecode(): data error in %s on line %d


Notice: fread(): zlib: data error in %s on line %d
read: bool(false)
gzdecode(): data error
zlib: data error
gzdecode(): data error
zlib: data error
15 changes: 11 additions & 4 deletions ext/zlib/tests/bug_52944.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ require __DIR__ . "/bug_52944_corrupted_data.inc";

$fp = fopen('data://text/plain;base64,' . $data, 'r');
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
var_dump(fread($fp,1));
var_dump(fread($fp,1));
try {
var_dump(fread($fp,1));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(fread($fp,1));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
fclose($fp);
echo "Done.\n";
?>
--EXPECTF--
Notice: fread(): zlib: data error in %s on line %d
bool(false)
zlib: data error
string(0) ""
Done.
10 changes: 6 additions & 4 deletions ext/zlib/tests/dictionary_usage.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ $r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]);
var_dump(inflate_add($r, $a, ZLIB_FINISH));

$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => ["8"] + range("a", "z")]);
var_dump(inflate_add($r, $a, ZLIB_FINISH));
try {
var_dump(inflate_add($r, $a, ZLIB_FINISH));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
string(%d) "%s"
bool(true)
string(6) "abdcde"

Warning: inflate_add(): Dictionary does not match expected dictionary (incorrect adler32 hash) in %s on line %d
bool(false)
Dictionary does not match expected dictionary (incorrect adler32 hash)
10 changes: 6 additions & 4 deletions ext/zlib/tests/gzinflate-bug42663.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ var_dump(strlen($deflated));
$truncated = substr($deflated, 0, 65535);
var_dump(strlen($truncated));
// inflate $truncated string (check if it will not eat all memory)
var_dump(gzinflate($truncated));
try {
var_dump(gzinflate($truncated));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
int(168890)
int(66743)
int(65535)

Warning: gzinflate(): data error in %s on line %d
bool(false)
data error
10 changes: 6 additions & 4 deletions ext/zlib/tests/gzinflate_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ $data = 'string_val';
$short_len = strlen($data) - 1;
$compressed = gzcompress($data);

var_dump(gzinflate($compressed, $short_len));
try {
var_dump(gzinflate($compressed, $short_len));
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
*** Testing gzinflate() : error conditions ***

-- Testing with a buffer that is too small --

Warning: gzinflate(): data error in %s on line %d
bool(false)
data error
11 changes: 6 additions & 5 deletions ext/zlib/tests/gzinflate_length.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
$unpacked=gzinflate($packed, strlen($original)*10);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";

$unpacked=gzinflate($packed, 1);
if ($unpacked === false) echo "Failed (as expected)\n";
try {
$unpacked=gzinflate($packed, 1);
} catch (\Throwable $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
5 15
Strings are equal
Strings are equal

Warning: gzinflate(): insufficient memory in %s on line %d
Failed (as expected)
insufficient memory
Loading