Repository navigation
Conversation
Member
|
so if it reproduces on 8.4, why did you target 8.5 ? |
devnexen
reviewed
Nov 25, 2026
Member
Author
good question, I don't remember, changing it |
gzwrite() returns 0 on error, never a negative value, so the compress.zlib:// wrapper reported a failed write as a successful write of 0 bytes. Return -1 when zlib reports an error and nothing was written.
lacatoire
force-pushed
the
fix/zlib-gzwrite-write-error-PHP-8.5
branch
from
November 25, 2026 19:35
8714249 to
b542e9d
Compare
Member
|
seems there is regression information wise. diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c
index 04dd7fa93dc..a30ae2fa169 100644
--- a/ext/zlib/zlib_fopen_wrapper.c
+++ b/ext/zlib/zlib_fopen_wrapper.c
@@ -78,6 +78,11 @@ static ssize_t php_gziop_write(php_stream *stream, const char *buf, size_t count
gzerror(self->gz_file, &error);
if (error != Z_OK && total_written == 0) {
+ if (error == Z_ERRNO && !(stream->flags & PHP_STREAM_FLAG_SUPPRESS_ERRORS)) {
+ char errstr[256];
+ php_error_docref(NULL, E_NOTICE, "Write of %u bytes failed with errno=%d %s",
+ chunk_size, errno, php_socket_strerror_s(errno, errstr, sizeof(errstr)));
+ }
return -1;
}
return total_written;
diff --git a/ext/zlib/tests/gzwrite_write_error.phpt b/ext/zlib/tests/gzwrite_write_error.phpt
index 0925eb2c17b..c496317db9c 100644
--- a/ext/zlib/tests/gzwrite_write_error.phpt
+++ b/ext/zlib/tests/gzwrite_write_error.phpt
@@ -11,9 +11,20 @@
$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));
?>
---EXPECT--
+--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) |
devnexen
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gzwrite()andfwrite()on acompress.zlib://stream reported success with 0 bytes when zlib failed to write (full disk, I/O error): the stream wrapper tested for a negative return, butgzwrite()returns 0 on error. The error is now reported when zlib setsZ_ERRNO, so the write returnsfalsewith a notice. A plain 0 on a stream opened for reading is unchanged.To reproduce:
Before (8.4.26 and 8.5.11):
After: