Edit File by line
/home/zeestwma/richards.../wp-inclu.../SimplePi.../src
File: Gzdecode.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* SimplePie
[3] Fix | Delete
*
[4] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[5] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[6] Fix | Delete
*
[7] Fix | Delete
* Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[8] Fix | Delete
* All rights reserved.
[9] Fix | Delete
*
[10] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[11] Fix | Delete
* permitted provided that the following conditions are met:
[12] Fix | Delete
*
[13] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[14] Fix | Delete
* conditions and the following disclaimer.
[15] Fix | Delete
*
[16] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[17] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[18] Fix | Delete
* provided with the distribution.
[19] Fix | Delete
*
[20] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[21] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[22] Fix | Delete
* written permission.
[23] Fix | Delete
*
[24] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[25] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[26] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[27] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[28] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[29] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[30] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[31] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[32] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[33] Fix | Delete
*
[34] Fix | Delete
* @package SimplePie
[35] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[36] Fix | Delete
* @author Ryan Parman
[37] Fix | Delete
* @author Sam Sneddon
[38] Fix | Delete
* @author Ryan McCue
[39] Fix | Delete
* @link http://simplepie.org/ SimplePie
[40] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[41] Fix | Delete
*/
[42] Fix | Delete
[43] Fix | Delete
namespace SimplePie;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Decode 'gzip' encoded HTTP data
[47] Fix | Delete
*
[48] Fix | Delete
* @package SimplePie
[49] Fix | Delete
* @subpackage HTTP
[50] Fix | Delete
* @link http://www.gzip.org/format.txt
[51] Fix | Delete
*/
[52] Fix | Delete
class Gzdecode
[53] Fix | Delete
{
[54] Fix | Delete
/**
[55] Fix | Delete
* Compressed data
[56] Fix | Delete
*
[57] Fix | Delete
* @access private
[58] Fix | Delete
* @var string
[59] Fix | Delete
* @see gzdecode::$data
[60] Fix | Delete
*/
[61] Fix | Delete
public $compressed_data;
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Size of compressed data
[65] Fix | Delete
*
[66] Fix | Delete
* @access private
[67] Fix | Delete
* @var int
[68] Fix | Delete
*/
[69] Fix | Delete
public $compressed_size;
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Minimum size of a valid gzip string
[73] Fix | Delete
*
[74] Fix | Delete
* @access private
[75] Fix | Delete
* @var int
[76] Fix | Delete
*/
[77] Fix | Delete
public $min_compressed_size = 18;
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Current position of pointer
[81] Fix | Delete
*
[82] Fix | Delete
* @access private
[83] Fix | Delete
* @var int
[84] Fix | Delete
*/
[85] Fix | Delete
public $position = 0;
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Flags (FLG)
[89] Fix | Delete
*
[90] Fix | Delete
* @access private
[91] Fix | Delete
* @var int
[92] Fix | Delete
*/
[93] Fix | Delete
public $flags;
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Uncompressed data
[97] Fix | Delete
*
[98] Fix | Delete
* @access public
[99] Fix | Delete
* @see gzdecode::$compressed_data
[100] Fix | Delete
* @var string
[101] Fix | Delete
*/
[102] Fix | Delete
public $data;
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Modified time
[106] Fix | Delete
*
[107] Fix | Delete
* @access public
[108] Fix | Delete
* @var int
[109] Fix | Delete
*/
[110] Fix | Delete
public $MTIME;
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Extra Flags
[114] Fix | Delete
*
[115] Fix | Delete
* @access public
[116] Fix | Delete
* @var int
[117] Fix | Delete
*/
[118] Fix | Delete
public $XFL;
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Operating System
[122] Fix | Delete
*
[123] Fix | Delete
* @access public
[124] Fix | Delete
* @var int
[125] Fix | Delete
*/
[126] Fix | Delete
public $OS;
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Subfield ID 1
[130] Fix | Delete
*
[131] Fix | Delete
* @access public
[132] Fix | Delete
* @see gzdecode::$extra_field
[133] Fix | Delete
* @see gzdecode::$SI2
[134] Fix | Delete
* @var string
[135] Fix | Delete
*/
[136] Fix | Delete
public $SI1;
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Subfield ID 2
[140] Fix | Delete
*
[141] Fix | Delete
* @access public
[142] Fix | Delete
* @see gzdecode::$extra_field
[143] Fix | Delete
* @see gzdecode::$SI1
[144] Fix | Delete
* @var string
[145] Fix | Delete
*/
[146] Fix | Delete
public $SI2;
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Extra field content
[150] Fix | Delete
*
[151] Fix | Delete
* @access public
[152] Fix | Delete
* @see gzdecode::$SI1
[153] Fix | Delete
* @see gzdecode::$SI2
[154] Fix | Delete
* @var string
[155] Fix | Delete
*/
[156] Fix | Delete
public $extra_field;
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Original filename
[160] Fix | Delete
*
[161] Fix | Delete
* @access public
[162] Fix | Delete
* @var string
[163] Fix | Delete
*/
[164] Fix | Delete
public $filename;
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Human readable comment
[168] Fix | Delete
*
[169] Fix | Delete
* @access public
[170] Fix | Delete
* @var string
[171] Fix | Delete
*/
[172] Fix | Delete
public $comment;
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Don't allow anything to be set
[176] Fix | Delete
*
[177] Fix | Delete
* @param string $name
[178] Fix | Delete
* @param mixed $value
[179] Fix | Delete
*/
[180] Fix | Delete
public function __set($name, $value)
[181] Fix | Delete
{
[182] Fix | Delete
throw new Exception("Cannot write property $name");
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Set the compressed string and related properties
[187] Fix | Delete
*
[188] Fix | Delete
* @param string $data
[189] Fix | Delete
*/
[190] Fix | Delete
public function __construct($data)
[191] Fix | Delete
{
[192] Fix | Delete
$this->compressed_data = $data;
[193] Fix | Delete
$this->compressed_size = strlen($data);
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Decode the GZIP stream
[198] Fix | Delete
*
[199] Fix | Delete
* @return bool Successfulness
[200] Fix | Delete
*/
[201] Fix | Delete
public function parse()
[202] Fix | Delete
{
[203] Fix | Delete
if ($this->compressed_size >= $this->min_compressed_size) {
[204] Fix | Delete
$len = 0;
[205] Fix | Delete
[206] Fix | Delete
// Check ID1, ID2, and CM
[207] Fix | Delete
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") {
[208] Fix | Delete
return false;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
// Get the FLG (FLaGs)
[212] Fix | Delete
$this->flags = ord($this->compressed_data[3]);
[213] Fix | Delete
[214] Fix | Delete
// FLG bits above (1 << 4) are reserved
[215] Fix | Delete
if ($this->flags > 0x1F) {
[216] Fix | Delete
return false;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
// Advance the pointer after the above
[220] Fix | Delete
$this->position += 4;
[221] Fix | Delete
[222] Fix | Delete
// MTIME
[223] Fix | Delete
$mtime = substr($this->compressed_data, $this->position, 4);
[224] Fix | Delete
// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
[225] Fix | Delete
if (current(unpack('S', "\x00\x01")) === 1) {
[226] Fix | Delete
$mtime = strrev($mtime);
[227] Fix | Delete
}
[228] Fix | Delete
$this->MTIME = current(unpack('l', $mtime));
[229] Fix | Delete
$this->position += 4;
[230] Fix | Delete
[231] Fix | Delete
// Get the XFL (eXtra FLags)
[232] Fix | Delete
$this->XFL = ord($this->compressed_data[$this->position++]);
[233] Fix | Delete
[234] Fix | Delete
// Get the OS (Operating System)
[235] Fix | Delete
$this->OS = ord($this->compressed_data[$this->position++]);
[236] Fix | Delete
[237] Fix | Delete
// Parse the FEXTRA
[238] Fix | Delete
if ($this->flags & 4) {
[239] Fix | Delete
// Read subfield IDs
[240] Fix | Delete
$this->SI1 = $this->compressed_data[$this->position++];
[241] Fix | Delete
$this->SI2 = $this->compressed_data[$this->position++];
[242] Fix | Delete
[243] Fix | Delete
// SI2 set to zero is reserved for future use
[244] Fix | Delete
if ($this->SI2 === "\x00") {
[245] Fix | Delete
return false;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
// Get the length of the extra field
[249] Fix | Delete
$len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
[250] Fix | Delete
$this->position += 2;
[251] Fix | Delete
[252] Fix | Delete
// Check the length of the string is still valid
[253] Fix | Delete
$this->min_compressed_size += $len + 4;
[254] Fix | Delete
if ($this->compressed_size >= $this->min_compressed_size) {
[255] Fix | Delete
// Set the extra field to the given data
[256] Fix | Delete
$this->extra_field = substr($this->compressed_data, $this->position, $len);
[257] Fix | Delete
$this->position += $len;
[258] Fix | Delete
} else {
[259] Fix | Delete
return false;
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
// Parse the FNAME
[264] Fix | Delete
if ($this->flags & 8) {
[265] Fix | Delete
// Get the length of the filename
[266] Fix | Delete
$len = strcspn($this->compressed_data, "\x00", $this->position);
[267] Fix | Delete
[268] Fix | Delete
// Check the length of the string is still valid
[269] Fix | Delete
$this->min_compressed_size += $len + 1;
[270] Fix | Delete
if ($this->compressed_size >= $this->min_compressed_size) {
[271] Fix | Delete
// Set the original filename to the given string
[272] Fix | Delete
$this->filename = substr($this->compressed_data, $this->position, $len);
[273] Fix | Delete
$this->position += $len + 1;
[274] Fix | Delete
} else {
[275] Fix | Delete
return false;
[276] Fix | Delete
}
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
// Parse the FCOMMENT
[280] Fix | Delete
if ($this->flags & 16) {
[281] Fix | Delete
// Get the length of the comment
[282] Fix | Delete
$len = strcspn($this->compressed_data, "\x00", $this->position);
[283] Fix | Delete
[284] Fix | Delete
// Check the length of the string is still valid
[285] Fix | Delete
$this->min_compressed_size += $len + 1;
[286] Fix | Delete
if ($this->compressed_size >= $this->min_compressed_size) {
[287] Fix | Delete
// Set the original comment to the given string
[288] Fix | Delete
$this->comment = substr($this->compressed_data, $this->position, $len);
[289] Fix | Delete
$this->position += $len + 1;
[290] Fix | Delete
} else {
[291] Fix | Delete
return false;
[292] Fix | Delete
}
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
// Parse the FHCRC
[296] Fix | Delete
if ($this->flags & 2) {
[297] Fix | Delete
// Check the length of the string is still valid
[298] Fix | Delete
$this->min_compressed_size += $len + 2;
[299] Fix | Delete
if ($this->compressed_size >= $this->min_compressed_size) {
[300] Fix | Delete
// Read the CRC
[301] Fix | Delete
$crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
[302] Fix | Delete
[303] Fix | Delete
// Check the CRC matches
[304] Fix | Delete
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) {
[305] Fix | Delete
$this->position += 2;
[306] Fix | Delete
} else {
[307] Fix | Delete
return false;
[308] Fix | Delete
}
[309] Fix | Delete
} else {
[310] Fix | Delete
return false;
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
// Decompress the actual data
[315] Fix | Delete
if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) {
[316] Fix | Delete
return false;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
$this->position = $this->compressed_size - 8;
[320] Fix | Delete
[321] Fix | Delete
// Check CRC of data
[322] Fix | Delete
$crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
[323] Fix | Delete
$this->position += 4;
[324] Fix | Delete
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
[325] Fix | Delete
{
[326] Fix | Delete
return false;
[327] Fix | Delete
}*/
[328] Fix | Delete
[329] Fix | Delete
// Check ISIZE of data
[330] Fix | Delete
$isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
[331] Fix | Delete
$this->position += 4;
[332] Fix | Delete
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) {
[333] Fix | Delete
return false;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
// Wow, against all odds, we've actually got a valid gzip string
[337] Fix | Delete
return true;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
return false;
[341] Fix | Delete
}
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
class_alias('SimplePie\Gzdecode', 'SimplePie_gzdecode');
[345] Fix | Delete
[346] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function