// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
// SPDX-License-Identifier: BSD-3-Clause
* Decode 'gzip' encoded HTTP data
* @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.
* Size of compressed data
* Minimum size of a valid gzip string
public $min_compressed_size = 18;
* Current position of pointer
* @see gzdecode::$compressed_data
* @see gzdecode::$extra_field
* @see gzdecode::$extra_field
* Don't allow anything to be set
public function __set(string $name, $value)
throw new Exception("Cannot write property $name");
* Set the compressed string and related properties
public function __construct(string $data)
$this->compressed_data = $data;
$this->compressed_size = strlen($data);
* @return bool Successfulness
if ($this->compressed_size >= $this->min_compressed_size) {
// Check ID1, ID2, and CM
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") {
$this->flags = ord($this->compressed_data[3]);
// FLG bits above (1 << 4) are reserved
if ($this->flags > 0x1F) {
// Advance the pointer after the above
$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((array) unpack('S', "\x00\x01")) === 1) {
$this->MTIME = current((array) unpack('l', $mtime));
// Get the XFL (eXtra FLags)
$this->XFL = ord($this->compressed_data[$this->position++]);
// Get the OS (Operating System)
$this->OS = ord($this->compressed_data[$this->position++]);
$this->SI1 = $this->compressed_data[$this->position++];
$this->SI2 = $this->compressed_data[$this->position++];
// SI2 set to zero is reserved for future use
if ($this->SI2 === "\x00") {
// Get the length of the extra field
$len = current((array) unpack('v', substr($this->compressed_data, $this->position, 2)));
// Check the length of the string is still valid
$this->min_compressed_size += $len + 4;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the extra field to the given data
$this->extra_field = substr($this->compressed_data, $this->position, $len);
// Get the length of the filename
$len = strcspn($this->compressed_data, "\x00", $this->position);
// Check the length of the string is still valid
$this->min_compressed_size += $len + 1;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the original filename to the given string
$this->filename = substr($this->compressed_data, $this->position, $len);
$this->position += $len + 1;
// Get the length of the comment
$len = strcspn($this->compressed_data, "\x00", $this->position);
// Check the length of the string is still valid
$this->min_compressed_size += $len + 1;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the original comment to the given string
$this->comment = substr($this->compressed_data, $this->position, $len);
$this->position += $len + 1;
// Check the length of the string is still valid
$this->min_compressed_size += $len + 2;
if ($this->compressed_size >= $this->min_compressed_size) {
$crc = current((array) unpack('v', substr($this->compressed_data, $this->position, 2)));
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) {
// Decompress the actual data
if (($data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) {
$this->position = $this->compressed_size - 8;
$crc = current((array) unpack('V', substr($this->compressed_data, $this->position, 4)));
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
$isize = current((array) unpack('V', substr($this->compressed_data, $this->position, 4)));
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) {
// Wow, against all odds, we've actually got a valid gzip string
class_alias('SimplePie\Gzdecode', 'SimplePie_gzdecode');