Simple Machines Community Forum

SMF Development => Bug Reports => Fixed or Bogus Bugs => Topic started by: dcmouser on December 29, 2019, 10:18:27 AM

Title: Bug in 2.016 can cause rss feeds to hang
Post by: dcmouser on December 29, 2019, 10:18:27 AM
Looks to me like the new 2.016 release has a bug in News.php serving rss feeds.  Took me a while to figure out why our server load was slowly growing out of control -- turns out some rss feeds were hanging in a php infinite loop.
In the function cdata_parse, 2.016 made a change to v2.015, replacing:
Code: [Select]
elseif ($smcFunc['substr']($data, $pos, 1) == ']')
{
$cdata .= ']]>&#093;<![CDATA[';
$pos++;
}

with

Code: [Select]
elseif ($smcFunc['substr']($data, $pos, 3) == ']]>')
{
$cdata .= ']]]]><![CDATA[>';
$pos = $pos + 3;
}

The problem is that the way the function is written, this can cause an infinite loop if it is parsing a post with a ] character in it, because there is no auto-incrementing of the $pos variable and it essentially keeps finding the same ']' and not advancing over it.  The $pos variable essentially loops forever without incrementing, causing an infinite loop.

One way to fix it is to add back in the old code from 2.015, another is to add a catch-all at the end of the elseif blocks like so:
Code: [Select]
else {
// ATTN: 12/29/19 alternate fix for bug introduced in 2.0.16, where $pos stays stuck on a [
// force advance $pos past this character
$pos++;
}

(Another way would be start the loop with $pos = -1 and check to make sure $pos>$old where it makes similar checks).

Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: Illori on December 29, 2019, 10:34:47 AM
we are well aware of this issue. we are working on getting a patch out to fix this.
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: m4z on December 29, 2019, 10:37:21 AM
Thanks for the detailed explanatation and fix! <3 You're awesome!
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: SleePy on December 29, 2019, 11:09:48 AM
In News.php

Find:
Code: [Select]
$positions = array(
$smcFunc['strpos']($data, '&', $pos),
$smcFunc['strpos']($data, ']', $pos),
);

Replace with:
Code: [Select]
$positions = array(
$smcFunc['strpos']($data, '&', $pos),
$smcFunc['strpos']($data, ']]>', $pos),
);

This will be fixed in the next release (2.0.17).  You will have to revert this change to get 2.0.17 to apply cleanly.
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: spiros on December 30, 2019, 04:11:30 AM
So if someone has not applied 2.0.16 yet, both 2.0.16 and 2.0.17 should be applied when updating?
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: m4z on December 30, 2019, 04:20:37 AM
As stated in the release announcement, that depends. If you use the incremental patches (https://wiki.simplemachines.org/smf/Patching), then yes. (But 2.0.17 isn't released yet.)
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: spiros on December 30, 2019, 04:28:10 AM
Thanks :)
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: shawnb61 on December 30, 2019, 02:49:26 PM
Confirmed & logged as #100. 
Title: Re: Bug in 2.016 can cause rss feeds to hang
Post by: shawnb61 on December 30, 2019, 10:32:38 PM
Fixed in 2.0.17