Skip to content

Commit 61dbb11

Browse files
External Libraries: Update the SimplePie library to version 1.5.7.
This version shows significant improvements in the compatibility of SimplePie with PHP 8.0, 8.1, and even contains an initial PHP 8.2 fix. The release also contains a number of other bug fixes. Release notes: https://github.com/simplepie/simplepie/releases/tag/1.5.7 For a full list of changes in this update, see the SimplePie GitHub: simplepie/simplepie@1.5.6...1.5.7 Follow-up to [47733], [49176]. Props jrf, SergeyBiryukov. Fixes #54659. git-svn-id: https://develop.svn.wordpress.org/trunk@52393 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e169c49 commit 61dbb11

11 files changed

Lines changed: 217 additions & 26 deletions

File tree

src/wp-includes/SimplePie/Cache/Redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function touch() {
152152
if ($data !== false) {
153153
$return = $this->cache->set($this->name, $data);
154154
if ($this->options['expire']) {
155-
return $this->cache->expire($this->name, $this->ttl);
155+
return $this->cache->expire($this->name, $this->options['expire']);
156156
}
157157
return $return;
158158
}

src/wp-includes/SimplePie/Enclosure.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,12 @@ public function get_real_type($find_handler = false)
11521152
// If we encounter an unsupported mime-type, check the file extension and guess intelligently.
11531153
if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
11541154
{
1155-
switch (strtolower($this->get_extension()))
1155+
$extension = $this->get_extension();
1156+
if ($extension === null) {
1157+
return null;
1158+
}
1159+
1160+
switch (strtolower($extension))
11561161
{
11571162
// Audio mime-types
11581163
case 'aac':

src/wp-includes/SimplePie/File.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function __construct($url, $timeout = 10, $redirects = 5, $headers = null
106106
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
107107
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
108108
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
109-
curl_setopt($fp, CURLOPT_REFERER, $url);
109+
curl_setopt($fp, CURLOPT_REFERER, SimplePie_Misc::url_remove_credentials($url));
110110
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
111111
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
112112
foreach ($curl_options as $curl_param => $curl_value) {
@@ -119,6 +119,7 @@ public function __construct($url, $timeout = 10, $redirects = 5, $headers = null
119119
curl_setopt($fp, CURLOPT_ENCODING, 'none');
120120
$this->headers = curl_exec($fp);
121121
}
122+
$this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
122123
if (curl_errno($fp))
123124
{
124125
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);

src/wp-includes/SimplePie/HTTP/Parser.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,13 @@ static public function prepareHeaders($headers, $count = 1)
507507
{
508508
$data = explode("\r\n\r\n", $headers, $count);
509509
$data = array_pop($data);
510-
if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n\r\n")) {
511-
$data = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $data);
510+
if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n")) {
511+
$exploded = explode("\r\n\r\n", $data, 2);
512+
$data = end($exploded);
512513
}
513-
if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n\r\n")) {
514-
$data = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $data);
514+
if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n")) {
515+
$exploded = explode("\r\n\r\n", $data, 2);
516+
$data = end($exploded);
515517
}
516518
return $data;
517519
}

src/wp-includes/SimplePie/Item.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ public function get_enclosures()
18031803
}
18041804
if (isset($content['attribs']['']['fileSize']))
18051805
{
1806-
$length = ceil($content['attribs']['']['fileSize']);
1806+
$length = intval($content['attribs']['']['fileSize']);
18071807
}
18081808
if (isset($content['attribs']['']['medium']))
18091809
{
@@ -2425,7 +2425,7 @@ public function get_enclosures()
24252425
}
24262426
if (isset($content['attribs']['']['fileSize']))
24272427
{
2428-
$length = ceil($content['attribs']['']['fileSize']);
2428+
$length = intval($content['attribs']['']['fileSize']);
24292429
}
24302430
if (isset($content['attribs']['']['medium']))
24312431
{
@@ -2790,7 +2790,7 @@ public function get_enclosures()
27902790
}
27912791
if (isset($link['attribs']['']['length']))
27922792
{
2793-
$length = ceil($link['attribs']['']['length']);
2793+
$length = intval($link['attribs']['']['length']);
27942794
}
27952795
if (isset($link['attribs']['']['title']))
27962796
{
@@ -2833,7 +2833,7 @@ public function get_enclosures()
28332833
}
28342834
if (isset($link['attribs']['']['length']))
28352835
{
2836-
$length = ceil($link['attribs']['']['length']);
2836+
$length = intval($link['attribs']['']['length']);
28372837
}
28382838

28392839
// Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
@@ -2862,13 +2862,14 @@ public function get_enclosures()
28622862
$width = null;
28632863

28642864
$url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
2865+
$url = $this->feed->sanitize->https_url($url);
28652866
if (isset($enclosure[0]['attribs']['']['type']))
28662867
{
28672868
$type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
28682869
}
28692870
if (isset($enclosure[0]['attribs']['']['length']))
28702871
{
2871-
$length = ceil($enclosure[0]['attribs']['']['length']);
2872+
$length = intval($enclosure[0]['attribs']['']['length']);
28722873
}
28732874

28742875
// Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor

src/wp-includes/SimplePie/Locator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SimplePie_Locator
6464
var $max_checked_feeds = 10;
6565
var $force_fsockopen = false;
6666
var $curl_options = array();
67+
var $dom;
6768
protected $registry;
6869

6970
public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array())
@@ -75,12 +76,19 @@ public function __construct(SimplePie_File $file, $timeout = 10, $useragent = nu
7576
$this->force_fsockopen = $force_fsockopen;
7677
$this->curl_options = $curl_options;
7778

78-
if (class_exists('DOMDocument'))
79+
if (class_exists('DOMDocument') && $this->file->body != '')
7980
{
8081
$this->dom = new DOMDocument();
8182

8283
set_error_handler(array('SimplePie_Misc', 'silence_errors'));
83-
$this->dom->loadHTML($this->file->body);
84+
try
85+
{
86+
$this->dom->loadHTML($this->file->body);
87+
}
88+
catch (Throwable $ex)
89+
{
90+
$this->dom = null;
91+
}
8492
restore_error_handler();
8593
}
8694
else

src/wp-includes/SimplePie/Misc.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,4 +2260,14 @@ public static function silence_errors($num, $str)
22602260
{
22612261
// No-op
22622262
}
2263+
2264+
/**
2265+
* Sanitize a URL by removing HTTP credentials.
2266+
* @param string $url the URL to sanitize.
2267+
* @return string the same URL without HTTP credentials.
2268+
*/
2269+
public static function url_remove_credentials($url)
2270+
{
2271+
return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
2272+
}
22632273
}

src/wp-includes/SimplePie/Parser.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,30 @@ public function parse(&$data, $encoding, $url = '')
164164
xml_set_element_handler($xml, 'tag_open', 'tag_close');
165165

166166
// Parse!
167-
if (!xml_parse($xml, $data, true))
167+
$wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory';
168+
if (($stream = fopen($wrapper, 'r+')) &&
169+
fwrite($stream, $data) &&
170+
rewind($stream))
171+
{
172+
//Parse by chunks not to use too much memory
173+
do
174+
{
175+
$stream_data = fread($stream, 1048576);
176+
if (!xml_parse($xml, $stream_data === false ? '' : $stream_data, feof($stream)))
177+
{
178+
$this->error_code = xml_get_error_code($xml);
179+
$this->error_string = xml_error_string($this->error_code);
180+
$return = false;
181+
break;
182+
}
183+
} while (!feof($stream));
184+
fclose($stream);
185+
}
186+
else
168187
{
169-
$this->error_code = xml_get_error_code($xml);
170-
$this->error_string = xml_error_string($this->error_code);
171188
$return = false;
172189
}
190+
173191
$this->current_line = xml_get_current_line_number($xml);
174192
$this->current_column = xml_get_current_column_number($xml);
175193
$this->current_byte = xml_get_current_byte_index($xml);

src/wp-includes/SimplePie/Registry.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ public function &call($type, $method, $parameters = array())
208208
{
209209
case 'Cache':
210210
// For backwards compatibility with old non-static
211-
// Cache::create() methods
211+
// Cache::create() methods in PHP < 8.0.
212+
// No longer supported as of PHP 8.0.
212213
if ($method === 'get_handler')
213214
{
214215
$result = @call_user_func_array(array($class, 'create'), $parameters);

src/wp-includes/SimplePie/Sanitize.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ class SimplePie_Sanitize
7171
var $useragent = '';
7272
var $force_fsockopen = false;
7373
var $replace_url_attributes = null;
74+
var $registry;
75+
76+
/**
77+
* List of domains for which to force HTTPS.
78+
* @see SimplePie_Sanitize::set_https_domains()
79+
* Array is a tree split at DNS levels. Example:
80+
* array('biz' => true, 'com' => array('example' => true), 'net' => array('example' => array('www' => true)))
81+
*/
82+
var $https_domains = array();
7483

7584
public function __construct()
7685
{
@@ -241,6 +250,68 @@ public function set_url_replacements($element_attribute = null)
241250
$this->replace_url_attributes = (array) $element_attribute;
242251
}
243252

253+
/**
254+
* Set the list of domains for which to force HTTPS.
255+
* @see SimplePie_Misc::https_url()
256+
* Example array('biz', 'example.com', 'example.org', 'www.example.net');
257+
*/
258+
public function set_https_domains($domains)
259+
{
260+
$this->https_domains = array();
261+
foreach ($domains as $domain)
262+
{
263+
$domain = trim($domain, ". \t\n\r\0\x0B");
264+
$segments = array_reverse(explode('.', $domain));
265+
$node =& $this->https_domains;
266+
foreach ($segments as $segment)
267+
{//Build a tree
268+
if ($node === true)
269+
{
270+
break;
271+
}
272+
if (!isset($node[$segment]))
273+
{
274+
$node[$segment] = array();
275+
}
276+
$node =& $node[$segment];
277+
}
278+
$node = true;
279+
}
280+
}
281+
282+
/**
283+
* Check if the domain is in the list of forced HTTPS.
284+
*/
285+
protected function is_https_domain($domain)
286+
{
287+
$domain = trim($domain, '. ');
288+
$segments = array_reverse(explode('.', $domain));
289+
$node =& $this->https_domains;
290+
foreach ($segments as $segment)
291+
{//Explore the tree
292+
if (isset($node[$segment]))
293+
{
294+
$node =& $node[$segment];
295+
}
296+
else
297+
{
298+
break;
299+
}
300+
}
301+
return $node === true;
302+
}
303+
304+
/**
305+
* Force HTTPS for selected Web sites.
306+
*/
307+
public function https_url($url)
308+
{
309+
return (strtolower(substr($url, 0, 7)) === 'http://') &&
310+
$this->is_https_domain(parse_url($url, PHP_URL_HOST)) ?
311+
substr_replace($url, 's', 4, 0) : //Add the 's' to HTTPS
312+
$url;
313+
}
314+
244315
public function sanitize($data, $type, $base = '')
245316
{
246317
$data = trim($data);
@@ -443,6 +514,7 @@ public function replace_urls($document, $tag, $attributes)
443514
$value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
444515
if ($value !== false)
445516
{
517+
$value = $this->https_url($value);
446518
$element->setAttribute($attribute, $value);
447519
}
448520
}

0 commit comments

Comments
 (0)