Skip to content

Commit

Permalink
PHP8: SimplePie wrong use of isset (#3404)
Browse files Browse the repository at this point in the history
#fix #3401 (crash with PHP 8+)

`ceil()` crashes in PHP8+ in case of invalid input such as empty string.
`intval()` fixes the problem with almost identical behaviour than `ceil()` in PHP7- (except for floating point values)

#fix #3401 (crash with PHP 8+)

Example with feed http://podcast.hr2.de/derTag/podcast.xml

```xml
<enclosure url="https://mp3podcasthr-a.akamaihd.net:443/mp3/podcast/derTag/derTag_20210129_87093232.mp3"
length="" type="audio/mpeg"/>
```

`isset("")` passes and then `ceil("")` crashes due to wrong type in PHP8+:

```
Uncaught TypeError: ceil(): Argument #1 ($num) must be of type
int|float, string given in ./SimplePie/SimplePie/Item.php:2871
```

Upstream patch simplepie/simplepie#670
  • Loading branch information
Alkarex committed Jan 31, 2021
1 parent 2b007ee commit 45ee7a3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/SimplePie/SimplePie/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ public function get_enclosures()
}
if (isset($content['attribs']['']['fileSize']))
{
$length = ceil($content['attribs']['']['fileSize']);
$length = intval($content['attribs']['']['fileSize']);
}
if (isset($content['attribs']['']['medium']))
{
Expand Down Expand Up @@ -2425,7 +2425,7 @@ public function get_enclosures()
}
if (isset($content['attribs']['']['fileSize']))
{
$length = ceil($content['attribs']['']['fileSize']);
$length = intval($content['attribs']['']['fileSize']);
}
if (isset($content['attribs']['']['medium']))
{
Expand Down Expand Up @@ -2790,7 +2790,7 @@ public function get_enclosures()
}
if (isset($link['attribs']['']['length']))
{
$length = ceil($link['attribs']['']['length']);
$length = intval($link['attribs']['']['length']);
}
if (isset($link['attribs']['']['title']))
{
Expand Down Expand Up @@ -2833,7 +2833,7 @@ public function get_enclosures()
}
if (isset($link['attribs']['']['length']))
{
$length = ceil($link['attribs']['']['length']);
$length = intval($link['attribs']['']['length']);
}

// Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
Expand Down Expand Up @@ -2868,7 +2868,7 @@ public function get_enclosures()
}
if (isset($enclosure[0]['attribs']['']['length']))
{
$length = ceil($enclosure[0]['attribs']['']['length']);
$length = intval($enclosure[0]['attribs']['']['length']);
}

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

0 comments on commit 45ee7a3

Please sign in to comment.