php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39616 gzuncompress() data error
Submitted: 2006-11-24 12:07 UTC Modified: 2015-03-13 09:49 UTC
From: emanuele at fondani dot it Assigned:
Status: Not a bug Package: Zlib related
PHP Version: 4.*, 5.* OS: Windows/Linux
Private report: No CVE-ID: None
 [2006-11-24 12:07 UTC] emanuele at fondani dot it
Description:
------------
PHP reports data error on function gzuncompress() when decompressing a particular gzipped string (see Reproduce code).

Reproduce code:
---------------
<?php
$gz_base64 = "SIl8VkFy2zgQvOsVc6S2YoQgQILcmx3HKaWcuMrW7iWVAyLBClIUqaUkp8rPyDf8hHwmxz3sI7YHICw5zm6lYkHwYNAz3T3w2Xzy8kKSpPntROZCV3lNOf6ltamkKAutSBZNI0xlELme5LSavHxzI2m1xXq+4B9fJ9ml3fnO0tVq5afzL5OTWuSlqelECl3UFc3PJ9k7Nyz61i3/oaKg9/2dW38aHBV5XvGJlxdFhFJo0eRVFaCkdVGKMq8YSV2KIpc1I8mKcPD1HBDe4P9bHPhCUuSFpK+ogt7Rh485LSeSPE1iCpJKGmQoaD2pZRliH7fayc2kEI1pcPwxvjBKKEBI8YcdDj/jHqoROM5KLSPwcV1UtWiamk/VWphcVYz8JOeLDXfvQ/ZO3Iiz2elUldmb2RVNP87fHjWjEXUNQCHnuFa1EY3SzfOcsgo5s4ur9+czil39H3C6wZlS/Te47PL1+6vL09RlUaLPoFPUWqO/TSVyhRLLXBhV0okBwKIqaXBoDFOSqJhUDVjTJRmWljFHvU877WOMqvBpjvlJO23i5JBGSyUkZHZIM4YcsqSQQxaAEwYqNqXCIU2gR+jSEMtdV5As619yGbeIVKFmI7jhRV6DeU7aaKGg4nGj/UXEuCGlFoVUKaR83EBInQtZqqOQm3DfaqKrRlQN86JFZTSNiJ4gC8pLKlEgNFeR3HEtywYLyZ5RBgQ1Jrk3EAxJwrYfsllLq2G/2fS06Lutb70dprLOHD1cTIsy67ulpz+nymR+KvPsjn/Y7/Q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m6DIgiCj6MLITftPZ3MeTRWngIsPAmGw7jxsxYMVo88fvQhV6s39PWYwS1ahhRWDT1ZMW9GRzzQNM46lH5sVvDf8BrQ7Hnfxi13iTYLZDxtpgfG4Dq/8vwIMAJ6YHA==";
$gz = base64_decode($gz_base64);

echo gzuncompress($gz);
?>

Expected result:
----------------
BT
/F1 1 Tf
10.4608 0 0 10.4608 761.5243 1299.7671 Tm
0 g
/GS1 gs
0 Tc
0 Tw
(Latina Oggi)Tj
-8.0578 -1.4286 TD
(Mercoled? 22 Novembre 2006)Tj
/F2 1 Tf
24.9066 0 0 24.9066 25.5063 1285.2018 Tm
(26)Tj
ET
0 G
0 J 0 j 1.021 w 10 M []0 d
1 i 
25.506 1317.202 m
815.021 1317.202 l
S
2.979 w 
25.506 1273.366 m
815.02 1273.366 l
S
BT
/F3 1 Tf
22.9141 0 0 22.9141 268.9982 1284.7036 Tm
-0.0217 Tc
[(M.S.BIA)35(GIO )]TJ
/F2 1 Tf
29.8879 0 0 29.8879 387.9349 1284.7036 Tm
-0.0167 Tc
(FONDI )Tj
/F3 1 Tf
22.9141 0 0 22.9141 490.0532 1284.7036 Tm
-0.0217 Tc
(LENOLA)Tj
ET
0.5 G
428.844 1096.031 250.735 -729.265 re
S
0 G
1.021 w 
695.245 710.477 m
815.021 710.477 l
695.245 365.272 m
815.021 365.272 l
25.506 710.477 m
413.178 710.477 l
25.506 365.272 m
413.178 365.272 l
S
0.7 g
753.474 982.457 61.546 -10.461 re
f
0.3 G
427.349 208.36 m
494.322 208.36 l
427.349 208.36 m
427.349 114.213 l
427.35 114.213 m
480.153 114.213 l
S
0.3 g
469.692 124.674 10.461 -10.461 re
f
BT
/F2 1 Tf
23.9103 0 0 23.9103 159.9113 1237.7397 Tm
0 g
-0.0282 Tw
[(Il gruppo consiliar)18(e ?F)25(ondi V)37(i)10(v)10(a? ? sul piede di guerra)]TJ
/F4 1 Tf
57.4446 0 0 61.7684 253.06 1180.9526 Tm
-0.053 Tc
-0.0078 Tw
[(?Raccolta rif)19.9(iuti,)]TJ
-0.8947 -0.9839 TD
(gestione poco chiara?)Tj
10.672 0 0 10.3611 25.5063 1149.8295 Tm
0.1124 Tc
0.2495 Tw
[(RA)39.7(CCOL)91.5(T)92.4(A)0( RIFIUTI,)]TJ
0 -1.0096 TD
-0.0084 Tc
0.269 Tw
(scuola ed incarichi esterni:)Tj
T*
0.1027 Tw
[(sono questi)-344.2(i temi)-344.2(per cui)-344.2(il)]TJ
T*
-0.0216 Tw
[(gruppo consigliare di ?F)14.8(ondi)]TJ
T*
-0.0039 Tw
[(vi)24.8(v)24.8(a? si prepara a dare batta)-8.4(-)]TJ
T*
0.1454 Tw
(glia in Consiglio comunale.)Tj
T*
0.1453 Tw
(In vista dell?assise cittadina)Tj
T*
0.1935 Tw
[(che)-435(si terr?)-435(v)14.8(enerd? sera,)-435(il)]TJ
T*
0.0246 Tw
[(gruppo di minoranza ha pre)-8.4(-)]TJ
T*
-0.0067 Tc
0.3687 Tw
(sentato all?amministrazione)Tj
T*
-0.0086 Tc
0.2454 Tw
(comunale un?interrogazione)Tj
T*
-0.0084 Tc
0.3539 Tw
[(in cui)-595.4(si chiede)-595.4(maggiore)]TJ
T*
0.1772 Tw
[(chiarezza)-418.7(sulla gestione)-418.7(del)]TJ
T*
-0.0132 Tw
[(servizio di raccolta dei rif)19.9(iuti)]TJ
T*
-0.0784 Tw
[(attualmente appaltato alla so)-8.4(-)]TJ
T*
0.2398 Tw
[(ciet? ?De V)59.6(izia?.)-481.3(?I sotto)-8.4(-)]TJ
T*
-0.0252 Tw
[(scritti Raf)24.8(fele De Bonis, Fer)-8.4(-)]TJ
T*
0.1504 Tw
[(nando)-391.9(Di F)14.8(azio)-391.9(ed)-391.9(Arnaldo)]TJ
T*
0.0127 Tw
[(F)14.8(aiola - si le)14.8(gge nell?interro)-8.4(-)]TJ
T*
-0.0086 Tc
-0.031 Tw
[(gazione a f)19.7(irma dei tre consi)-8.6(-)]TJ
T*
0.0734 Tw
[(glieri - chiedono)-314.9(che v)14.6(enga)-8.6(-)]TJ
T*
-0.0084 Tc
0.2059 Tw
[(no f)9.9(atte)-447.5(alcune v)14.8(erif)19.9(iche)-447.5(in)]TJ
T*
0.0389 Tw
[(merito alla societ? De V)59.6(izia.)]TJ
T*
0.0636 Tw
(Innanzitutto occorre chiarire)Tj
T*
0.1103 Tw
[(se)-351.9(la ditta)-351.9(stia rispettando)-351.9(il)]TJ
T*
0.2527 Tw
[(contratto)-494.2(sottoscritto con)-494.2(il)]TJ
T*
-0.0032 Tw
(comune ed in particolare se i)Tj
T*
0.106 Tw
[(mezzi per)-347.6(la raccolta)-347.6(dei ri)-8.4(-)]TJ
T*
0.0783 Tw
[(f)19.9(iuti)-319.8(oltre)-319.8(ad essere)-319.8(a)-319.8(norma)]TJ

Actual result:
--------------
<br />
<b>Warning</b>:  gzuncompress() [<a href='function.gzuncompress'>function.gzuncompress</a>]: data error in <b>C:\Inetpub\wwwroot\test\test2.php</b> on line <b>9</b><br />


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 12:24 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2006-11-24 12:36 UTC] emanuele at fondani dot it
Please be more specific. Where can I get more information about this problem?
What are the "support channels" you mean? Can you suggest a link?

Thank you
 [2006-11-27 12:07 UTC] mgf@php.net
There's a suggested link in tony2001's message.  Mailing lists and newsgroups are usually good support channels.
 [2009-11-20 09:03 UTC] emanuele at fondani dot it
I found that the issue is due to the fact that in some cases in the gzipped pdf stream the zlib stream header (see RFC 1950) is missing or invalid, and the gzuncompress() function cannot decompress data.

Here's my workaround to fix the problem: I wrote a new ZlibDecompress class in PHP from some original C++ code by Mark Adler taken from the official zlib site, which uses the standard algorithm and always decompress the string correctly, ignoring the zlib stream header, as it contains only CRC data. 
Obviously this PHP class is much more slower than gzuncompress function, because it is not compiled, so I use it only when gzuncompress fails. For pdf files this happens only in a few cases, so this is a good compromise for me.

If anyone is interested please contact me by email and I will send the class file.
 [2010-11-29 01:17 UTC] emanuele at fondani dot it
After many email requests for the code, i published it as a google code project.
You can download it at: http://code.google.com/p/zlibdecompress/
 [2015-03-13 07:34 UTC] emanuele at fondani dot it
As Google Code is closing, I've moved the code to github:
https://github.com/eiannone/zlibdecompress
 [2015-03-13 09:49 UTC] mike@php.net
Did you try zlib_decode() yet? (since PHP-5.4)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat May 25 23:01:27 2019 UTC