Edit report at https://bugs.php.net/bug.php?id=80953&edit=1
ID: 80953
Updated by: cmb@php.net
Reported by: tessus@php.net
Summary: gzencode(): stream error
Status: Feedback
Type: Bug
Package: Zlib related
Operating System: Linux
PHP Version: 7.4.16
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> zlib_version() tells me undefined function in the php shell.
Oh indeed, the proper spelling is zlibVersion(), and that function
is used to retrieve the linked version[1]. To my knowlege, PHP does
not (and never did) bundle zlib, so this old version must be somewhere
on your system. I assume that the difference between PHP 7.3 and 7.4
is due to build system changes; 7.4 uses pkg-config to detect zlib[2]
while 7.3 manually searched for the lib in the usual places[3].
Anyhow, what does
pkg-config --print-provides zlib
report?
[1] <https://github.com/php/php-src/blob/php-7.4.16/ext/zlib/zlib.c#L1593>
[2] <https://github.com/php/php-src/blob/php-7.4.16/ext/zlib/config0.m4>
[3] <https://github.com/php/php-src/blob/php-7.3.27/ext/zlib/config0.m4>
Previous Comments:
------------------------------------------------------------------------
[2021-04-13 15:58:19] tessus@php.net
zlib_version() tells me undefined function in the php shell. But:
php > echo ZLIB_VERSION;
1.2.8
But then I looked at the phpinfo() output and found something very strange:
ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.8
Linked Version => 1.1.3
My zlib version on the system is 1.2.8. There is nowhere a 1.1.3 in any of my lib directories.
And on PHP 7.3 both match and say 1.2.8.
I can assure you that there is no 1.1.3 of zlib on my system and I have no idea where this is coming
from. ldd for my php 7.4 binary shows:
libz.so.1 => /usr/lib64/libz.so.1 (0x00000036d3200000)
and ls -la /usr/lib64/libz.so.1 shows: /usr/lib64/libz.so.1 -> libz.so.1.2.8
I just compiled 7.3 again and all works. I compile 7.4 and same problem. It's very puzzling,
since I certainly haven't installed libz 1.1.3, nor is it present in any of my lib paths. (Why
would I install an older version?) Also, in that case 7.3, would pick it up too.
We have a mystery on our hands.
The only logical explanation would be that PHP 7.4 bundles 1.1.3 and statically links it.
------------------------------------------------------------------------
[2021-04-13 11:14:39] cmb@php.net
> PHP Warning: gzencode(): stream error in t.php on line 3
This is apparently caused by deflateInit2()[1] returning
Z_STREAM_ERROR. The zlib manual[2] states:
| deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
| not enough memory, Z_STREAM_ERROR if a parameter is invalid (such
| as an invalid method), or Z_VERSION_ERROR if the zlib library
| version (zlib_version) is incompatible with the version assumed by
| the caller (ZLIB_VERSION).
Does zlib_version() match ZLIB_VERSION for you?
[1] <https://github.com/php/php-src/blob/php-7.4.16/ext/zlib/zlib.c#L346>
[2] <https://zlib.net/manual.html>
------------------------------------------------------------------------
[2021-04-12 17:49:32] tessus@php.net
Description:
------------
I've tested it with PHP 7.4.15 and PHP 7.4.16.
I get errors with zlib related functions. e.g. for the test script below, I get the following
warning, which should be an error in the first place, because the resulting file is invalid.
PHP Warning: gzencode(): stream error in t.php on line 3
It happens with cli and php-fpm. I do have read/write access to the directory where the file
bigfile.txt is located.
I've tested this with 7.3.27 and it works without issues. I compile PHP myself and there were
no errors in config.log, nor during compilation. configure stated for both PHP releases that zlib
was found and ok to use.
Test script:
---------------
<?php
$data = implode("", file("bigfile.txt"));
$gzdata = gzencode($data, 9);
$fp = fopen("bigfile.txt.gz", "w");
fwrite($fp, $gzdata);
fclose($fp);
?>
Expected result:
----------------
The file should be compressed and the result should be a valid bigfile.txt.gz
Actual result:
--------------
A file bigfile.txt.gz is created with 0 bytes.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80953&edit=1