Open NickHahac opened 6 months ago
We need a little bit more information. What PHP version do you run? I assume you tried 2.8.0-RC2?
Can you provide the PDF which causes this behavior? If not, try to debug to the point where the error is triggered and give us the parameters of the functions so we can reproduce the error locally.
And last, why did you reference #622?
PHP version is 7.4.2
This error appears in Smalot/PdfParser/RawData/FilterHelper. php: 241
Function is:
/**
* FlateDecode
*
* Decompresses data encoded using the zlib/deflate compression method, reproducing the original text or binary data.
*
* @param string $data Data to decode
* @param int $decodeMemoryLimit Memory limit on deflation
*
* @return string data string
*
* @throws \Exception
*/
protected function decodeFilterFlateDecode(string $data, int $decodeMemoryLimit): ?string
{
// Uncatchable E_WARNING for "data error" is @ suppressed
// so execution may proceed with an alternate decompression
// method.
$decoded = @gzuncompress($data, $decodeMemoryLimit);
if (false === $decoded) {
// If gzuncompress() failed, try again using the compress.zlib://
// wrapper to decode it in a file-based context.
// See: https://www.php.net/manual/en/function.gzuncompress.php#79042
// Issue: https://github.com/smalot/pdfparser/issues/592
$ztmp = tmpfile();
if (false != $ztmp) {
fwrite($ztmp, "\x1f\x8b\x08\x00\x00\x00\x00\x00".$data);
$file = stream_get_meta_data($ztmp)['uri'];
if (0 === $decodeMemoryLimit) {
$decoded = file_get_contents('compress.zlib://'.$file);
} else {
$decoded = file_get_contents('compress.zlib://'.$file, false, null, 0, $decodeMemoryLimit);
}
fclose($ztmp);
}
}
if (false === \is_string($decoded) || '' === $decoded) {
// If the decoded string is empty, that means decoding failed.
throw new \Exception('decodeFilterFlateDecode: invalid data');
}
return $decoded;
}
params is
$data = "�s��8�S4z�2A�ٮ�������n�O��)q,�ӕ�ik�7l�B:��<Lgz?��C�/�UL�"XZ�@���ui~-�����٥~�&K��"&8_�E����A�f
@.***�Kj��s����!3�Q�<�������#
ŀ>�����3�|�L"
$decodeMemoryLimit = 1000000
At 2023-12-20 16:07:38, "Konrad Abicht" @.***> wrote:
We need a little bit more information. What PHP version do you run? I assume you tried 2.8.0-RC?
Can you provide the PDF which causes this behavior? If not, try to debug to the point where the error is triggered and give us the parameters of the functions so we can reproduce the error locally.
And last, why did you reference #622?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
HI, k00ni Hope everything goes well with you.
Is there a way to solve this problem, I hope to receive your help!
Can you help me solve my problem?
Sorry for the late response, I hope I can get back to you the next week.
Hi k00ni Thank you for your reply.
If you need to reproduce this error, you can do it like this, $decoded in the code will return false. At the same time, you can see the error "[error] [2] gzuncompress(): data error" in PHP error. log
Please run this code to reproduce the issue
/**
@throws \Exception */ protected function decodeFilterFlateDecode(string $data, int $decodeMemoryLimit): ?string { // Uncatchable E_WARNING for "data error" is @ suppressed // so execution may proceed with an alternate decompression // method.
$data = '�s��8�S4z�2A�ٮ��������n�O���)q,�ӕ�ik�7l�B:��<Lgz?��C�/�UL�"XZ�@���ui~-�����٥~�&K��"&8_�E����A�f***@***.***�Kj��s����!3�Q�<�������#ŀ>�����3�|�L';
$decodeMemoryLimit = 1000000;
$decoded = @gzuncompress($data, $decodeMemoryLimit);
var_dump($decoded);die();
if (false === $decoded) {
// If gzuncompress() failed, try again using the compress.zlib://
// wrapper to decode it in a file-based context.
// See: https://www.php.net/manual/en/function.gzuncompress.php#79042
// Issue: https://github.com/smalot/pdfparser/issues/592
$ztmp = tmpfile();
if (false != $ztmp) {
fwrite($ztmp, "\x1f\x8b\x08\x00\x00\x00\x00\x00".$data);
$file = stream_get_meta_data($ztmp)['uri'];
if (0 === $decodeMemoryLimit) {
$decoded = file_get_contents('compress.zlib://'.$file);
} else {
$decoded = file_get_contents('compress.zlib://'.$file, false, null, 0, $decodeMemoryLimit);
}
fclose($ztmp);
}
}
if (false === \is_string($decoded) || '' === $decoded) {
// If the decoded string is empty, that means decoding failed.
throw new \Exception('decodeFilterFlateDecode: invalid data');
}
return $decoded;
}
Might this have something to do with your PHP version? You're using 7.4.2. I'm using 8.3.0 and can't reproduce your error with the code you've given. No errors appear in my PHP error log.
If it is a problem with the PHP version, can you fix this issue with compatibility? I hope this error will not be reported in version 7.4.2
I hope this error will not be reported in version 7.4.2
Can we assume you have to use PHP 7.4.2?
I encountered a problem while using it.
Attempting to update to the latest version, the issue still exists. How should I block this exception.
https://github.com/smalot/pdfparser/pull/622