diff options
Diffstat (limited to 'src/Gzdecode.php')
| -rw-r--r-- | src/Gzdecode.php | 69 |
1 files changed, 16 insertions, 53 deletions
diff --git a/src/Gzdecode.php b/src/Gzdecode.php index 67cbfef..2c97707 100644 --- a/src/Gzdecode.php +++ b/src/Gzdecode.php @@ -1,56 +1,18 @@ <?php +// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue +// SPDX-License-Identifier: BSD-3-Clause + declare(strict_types=1); -/** - * SimplePie - * - * A PHP-Based RSS and Atom Feed Framework. - * Takes the hard work out of managing a complete RSS/Atom solution. - * - * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * * Neither the name of the SimplePie Team nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS - * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package SimplePie - * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue - * @author Ryan Parman - * @author Sam Sneddon - * @author Ryan McCue - * @link http://simplepie.org/ SimplePie - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - */ namespace SimplePie; /** * Decode 'gzip' encoded HTTP data * - * @package SimplePie - * @subpackage HTTP * @link http://www.gzip.org/format.txt + * @link https://www.php.net/manual/en/function.gzdecode.php + * @deprecated since SimplePie 1.9.0, use `gzdecode` function instead. */ class Gzdecode { @@ -180,9 +142,9 @@ class Gzdecode * @param string $name * @param mixed $value */ - public function __set($name, $value) + public function __set(string $name, $value) { - trigger_error("Cannot write property $name", E_USER_ERROR); + throw new Exception("Cannot write property $name"); } /** @@ -190,7 +152,7 @@ class Gzdecode * * @param string $data */ - public function __construct($data) + public function __construct(string $data) { $this->compressed_data = $data; $this->compressed_size = strlen($data); @@ -225,10 +187,10 @@ class Gzdecode // MTIME $mtime = substr($this->compressed_data, $this->position, 4); // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness - if (current(unpack('S', "\x00\x01")) === 1) { + if (current((array) unpack('S', "\x00\x01")) === 1) { $mtime = strrev($mtime); } - $this->MTIME = current(unpack('l', $mtime)); + $this->MTIME = current((array) unpack('l', $mtime)); $this->position += 4; // Get the XFL (eXtra FLags) @@ -249,7 +211,7 @@ class Gzdecode } // Get the length of the extra field - $len = current(unpack('v', substr($this->compressed_data, $this->position, 2))); + $len = current((array) unpack('v', substr($this->compressed_data, $this->position, 2))); $this->position += 2; // Check the length of the string is still valid @@ -301,7 +263,7 @@ class Gzdecode $this->min_compressed_size += $len + 2; if ($this->compressed_size >= $this->min_compressed_size) { // Read the CRC - $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2))); + $crc = current((array) unpack('v', substr($this->compressed_data, $this->position, 2))); // Check the CRC matches if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) { @@ -315,14 +277,15 @@ class Gzdecode } // Decompress the actual data - if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) { + if (($data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) { return false; } + $this->data = $data; $this->position = $this->compressed_size - 8; // Check CRC of data - $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4))); + $crc = current((array) unpack('V', substr($this->compressed_data, $this->position, 4))); $this->position += 4; /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc)) { @@ -330,7 +293,7 @@ class Gzdecode }*/ // Check ISIZE of data - $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4))); + $isize = current((array) unpack('V', substr($this->compressed_data, $this->position, 4))); $this->position += 4; if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) { return false; |
