![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Chronopost/Chronorelais/Lib/Fpdi/PdfParser/Filter/ |
<?php /** * This file is part of FPDI * * @package Chronopost\Chronorelais\Lib\Fpdi * @copyright Copyright (c) 2020 Chronopost\Chronorelais\Lib GmbH & Co. KG (https://www.Chronopost\Chronorelais\Lib.com) * @license http://opensource.org/licenses/mit-license The MIT License */ namespace Chronopost\Chronorelais\Lib\Fpdi\PdfParser\Filter; /** * Class for handling zlib/deflate encoded data * * @package Chronopost\Chronorelais\Lib\Fpdi\PdfParser\Filter */ class Flate implements FilterInterface { /** * Checks whether the zlib extension is loaded. * * Used for testing purpose. * * @return boolean * @internal */ protected function extensionLoaded() { return \extension_loaded('zlib'); } /** * Decodes a flate compressed string. * * @param string $data The input string * @return string * @throws FlateException */ public function decode($data) { if ($this->extensionLoaded()) { $oData = $data; $data = @((\strlen($data) > 0) ? \gzuncompress($data) : ''); if ($data === false) { // let's try if the checksum is CRC32 $fh = fopen('php://temp', 'w+b'); fwrite($fh, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $oData); stream_filter_append($fh, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 30]); fseek($fh, 0); $data = stream_get_contents($fh); fclose($fh); if ($data) { return $data; } // Try this fallback $tries = 0; $oDataLen = strlen($oData); while ($tries < 6 && ($data === false || (strlen($data) < (strlen($oDataLen) - $tries - 1)))) { $data = @(gzinflate(substr($oData, $tries))); $tries++; } // let's use this fallback only if the $data is longer than the original data if (strlen($data) > ($oDataLen - $tries - 1)) { return $data; } if (!$data) { throw new FlateException( 'Error while decompressing stream.', FlateException::DECOMPRESS_ERROR ); } } } else { throw new FlateException( 'To handle FlateDecode filter, enable zlib support in PHP.', FlateException::NO_ZLIB ); } return $data; } }