[php-src] master: zlib: Add test with invalid levels

From: Date: Mon, 10 Aug 2026 18:23:50 +0000
Subject: [php-src] master: zlib: Add test with invalid levels
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140605@lists.php.net to get a copy of this message
Author: Gina Peter Banyard (Girgias) Date: 2026-08-10T19:23:47+01:00 Commit: https://github.com/php/php-src/commit/1cf82bef0a7e3c85b40eff2539ab6c9878dcd872 Raw diff: https://github.com/php/php-src/commit/1cf82bef0a7e3c85b40eff2539ab6c9878dcd872.diff zlib: Add test with invalid levels Changed paths: A ext/zlib/tests/zlib_wrapper_level_errors.phpt Diff: diff --git a/ext/zlib/tests/zlib_wrapper_level_errors.phpt b/ext/zlib/tests/zlib_wrapper_level_errors.phpt new file mode 100644 index 000000000000..cc586da568b1 --- /dev/null +++ b/ext/zlib/tests/zlib_wrapper_level_errors.phpt @@ -0,0 +1,45 @@ +--TEST-- +compress.zlib:// wrapper with invalid compression level +--EXTENSIONS-- +zlib +--SKIPIF-- +<?php +in_array('compress.zlib', stream_get_wrappers()) || die('skip No zlib wrapper'); +?> +--FILE-- +<?php declare(strict_types=1); + +$filename = tempnam(sys_get_temp_dir(), "php-zlib-test-wrapper-level-error"); +$thisfile = file_get_contents(__FILE__); + +function write_at_level(mixed $level) { + global $filename, $thisfile; + + $ctx = stream_context_create(); + stream_context_set_option($ctx, 'zlib', 'level', $level); + $fp = fopen("compress.zlib://$filename", 'w', false, $ctx); + for ($i = 0; $i < 10; ++$i) { + fwrite($fp, $thisfile); + } + fclose($fp); + $size = filesize($filename); + unlink($filename); + return $size; +} + +$size_string_type = write_at_level("not a number"); +var_dump($size_string_type); + +$size_array_type = write_at_level(new stdClass()); +var_dump($size_array_type); + +$size_oob = write_at_level(10000); +var_dump($size_oob); + +?> +--EXPECTF-- +int(%d) + +Warning: Object of class stdClass could not be converted to int in %s on line %d +int(%d) +int(0)

« previous php.cvs (#140605) next »