[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Thu, 26 Nov 2026 19:05:12 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144237@lists.php.net to get a copy of this message
Author: David Carlier (devnexen) Date: 2026-11-26T19:03:41Z Commit: https://github.com/php/php-src/commit/070d4af33687e45a16905237b7eb8a5832c74ffa Raw diff: https://github.com/php/php-src/commit/070d4af33687e45a16905237b7eb8a5832c74ffa.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: ext/zlib: fix gzwrite() not reporting write errors Changed paths: A ext/zlib/tests/gzwrite_write_error.phpt M ext/zlib/zlib_fopen_wrapper.c Diff: diff --git a/ext/zlib/tests/gzwrite_write_error.phpt b/ext/zlib/tests/gzwrite_write_error.phpt new file mode 100644 index 000000000000..c496317db9ce --- /dev/null +++ b/ext/zlib/tests/gzwrite_write_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +gzwrite(), fwrite() on compress.zlib://: a write error is reported +--EXTENSIONS-- +zlib +--SKIPIF-- +<?php +if (!file_exists('/dev/full')) die('skip needs /dev/full'); +?> +--FILE-- +<?php +$data = random_bytes(300000); +$w = gzopen('/dev/full', 'w'); +var_dump(gzwrite($w, $data)); +var_dump(gzwrite($w, 'x')); +$f = fopen('compress.zlib:///dev/full', 'w'); +var_dump(fwrite($f, $data)); +var_dump(file_put_contents('compress.zlib:///dev/full', $data)); +?> +--EXPECTF-- +Notice: gzwrite(): Write of 300000 bytes failed with errno=%d %s in %s on line %d +bool(false) + +Notice: gzwrite(): Write of 1 bytes failed with errno=%d %s in %s on line %d +bool(false) + +Notice: fwrite(): Write of 300000 bytes failed with errno=%d %s in %s on line %d +bool(false) + +Notice: file_put_contents(): Write of 300000 bytes failed with errno=%d %s in %s on line %d +bool(false) diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index 2b922bf1d11e..47df31917896 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -77,18 +77,24 @@ static ssize_t php_gziop_write(php_stream *stream, const char *buf, size_t count struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; ssize_t total_written = 0; - /* Despite the count argument of gzread() being "unsigned int", - * the return value is "int". Error returns are values < 0, otherwise the count is returned. - * To properly distinguish error values from success value, we therefore need to cap at INT_MAX. + /* Despite the count argument of gzwrite() being "unsigned int", + * the return value is "int". Error returns are 0, otherwise the count is returned. + * To keep the count representable in the return value, we therefore need to cap at INT_MAX. */ do { unsigned int chunk_size = MIN(count, INT_MAX); int written = gzwrite(self->gz_file, buf, chunk_size); count -= chunk_size; - if (UNEXPECTED(written < 0)) { - php_gziop_report_errors(stream, chunk_size, "Write"); - return written; + if (UNEXPECTED(written <= 0)) { + int error = Z_OK; + + gzerror(self->gz_file, &error); + if (error != Z_OK && total_written == 0) { + php_gziop_report_errors(stream, chunk_size, "Write"); + return -1; + } + return total_written; } total_written += written;

« previous php.cvs (#144237) next »