Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzuncompress(): data error #659

Closed
NickHahac opened this issue Dec 20, 2023 · 9 comments
Closed

gzuncompress(): data error #659

NickHahac opened this issue Dec 20, 2023 · 9 comments

Comments

@NickHahac
Copy link

I encountered a problem while using it.

image

Attempting to update to the latest version, the issue still exists.
How should I block this exception.

#622

@k00ni
Copy link
Collaborator

k00ni commented Dec 20, 2023

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?

@NickHahac
Copy link
Author

NickHahac commented Dec 20, 2023 via email

@NickHahac
Copy link
Author

HI, k00ni
Hope everything goes well with you.

Is there a way to solve this problem, I hope to receive your help!

@NickHahac
Copy link
Author

Can you help me solve my problem?

@k00ni
Copy link
Collaborator

k00ni commented Feb 28, 2024

Sorry for the late response, I hope I can get back to you the next week.

@NickHahac
Copy link
Author

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

/**
* 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.

    $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;
}

@GreyWyvern
Copy link
Contributor

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.

@NickHahac
Copy link
Author

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

@k00ni
Copy link
Collaborator

k00ni commented Apr 1, 2024

I hope this error will not be reported in version 7.4.2

Can we assume you have to use PHP 7.4.2?

@k00ni k00ni closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants