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