Repository navigation
simplepie: fix potential XML error: No memory when parsing huge feed - #8710
LeeXiaolan wants to merge 1 commit into
Conversation
After upgrade debian-based image from `freshrss:1.27.0` to `freshrss:1.28.1`, feed projectzero `https://projectzero.google/feed.xml` start failing to update, the log says `https://projectzero.google/feed.xml is invalid XML, likely due to invalid characters. XML error: No memory at line 1250, column 2167 [https://projectzero.google/feed.xml]`. According to the PHP doc[1]: > XML_OPTION_PARSE_HUGE (int) > Available as of PHP 8.4.0. When libxml2 < 2.7.0 is used (e.g. on PHP 7.x), this option is enabled by default and cannot be disabled. There is a new option `XML_OPTION_PARSE_HUGE` after PHP 8.4.0. And indeed there is an upgrade to PHP 8.4 between 1.27.0 and 1.28.1 in debian-based docker image. And the new default value is `false`[2]. Set this option to `1` fixed the problem for me. 1. https://www.php.net/manual/en/xml.constants.php#constant.xml-option-parse-huge 2. https://github.com/php/php-src/blob/90744ec52a50e0eacab47d5a51d82c1b26607b76/ext/xml/xml.c#L1116
Frenzie
left a comment
There was a problem hiding this comment.
Sounds good to me.
There is the aside that it should presumably go into https://github.com/FreshRSS/simplepie and preferably upstream as well, but @Alkarex normally deals with that.
@LeeXiaolan Could you please send the same PR to https://github.com/simplepie/simplepie ? Personally, I would slightly prefer a We also have to think of the drawbacks of activating this option (by default). We risk hitting more easily an out-of-memory condition (although it was the same before PHP 8.4), so it would be nice to improve how we handle this condition, in particular in a cron job of a system with multiple users. Another approach would be to make it a feed option. |
|
It's a pity that it's either a rather small limit or no limit at all. |
I just started a two-week-vacation, I will do it after back.
It seems |
…huge feed PHP 8.4.0 introduced a new option[1], which makes it behave differently. > XML_OPTION_PARSE_HUGE (int) > Available as of PHP 8.4.0. When libxml2 < 2.7.0 is used (e.g. on PHP 7.x), this option is enabled by default and cannot be disabled. The default value of this new option is `0`[2]. And this option is only effective when `libxml2` is used. `libexpat` totally ignores it[3]. This patch sets this option to `1`, the old default value, when this option is defined. So everything is consistent. Yes, this brings more risks of potential DoS attack, but it should be defended somewhere else. Because the whole XML string is already downloaded into the memory when parsing, bars could be placed during downloading, no matter which PHP version and XML lib is used. Downstream issue: FreshRSS/FreshRSS#8516 FreshRSS/FreshRSS#8710 1. https://www.php.net/manual/en/xml.constants.php#constant.xml-option-parse-huge 2. https://github.com/php/php-src/blob/90744ec52a50e0eacab47d5a51d82c1b26607b76/ext/xml/xml.c#L1116 3. https://wiki.php.net/rfc/xml_option_parse_huge Signed-off-by: Kidd Lee <[email protected]>
…huge feed PHP 8.4.0 introduced a new option[1], which makes it behave differently. > XML_OPTION_PARSE_HUGE (int) > Available as of PHP 8.4.0. When libxml2 < 2.7.0 is used (e.g. on PHP 7.x), this option is enabled by default and cannot be disabled. The default value of this new option is `0`[2]. And this option is only effective when `libxml2` is used. `libexpat` totally ignores it[3]. This patch sets this option to `1`, the old default value, when this option is defined. So everything is consistent. Yes, this brings more risks of potential DoS attack, but it should be defended somewhere else. Because the whole XML string is already downloaded into the memory when parsing, bars could be placed during downloading, no matter which PHP version and XML lib is used. Downstream issue: FreshRSS/FreshRSS#8516 FreshRSS/FreshRSS#8710 1. https://www.php.net/manual/en/xml.constants.php#constant.xml-option-parse-huge 2. https://github.com/php/php-src/blob/90744ec52a50e0eacab47d5a51d82c1b26607b76/ext/xml/xml.c#L1116 3. https://wiki.php.net/rfc/xml_option_parse_huge Signed-off-by: Kidd Lee <[email protected]>
…huge feed PHP 8.4.0 introduced a new option[1], which makes it behave differently. > XML_OPTION_PARSE_HUGE (int) > Available as of PHP 8.4.0. When libxml2 < 2.7.0 is used (e.g. on PHP 7.x), this option is enabled by default and cannot be disabled. The default value of this new option is `0`[2]. And this option is only effective when `libxml2` is used. `libexpat` totally ignores it[3]. This patch sets this option to `1`, the old default value, when this option is defined. So everything is consistent. Yes, this brings more risks of potential DoS attack, but it should be defended somewhere else. Because the whole XML string is already downloaded into the memory when parsing, bars could be placed during downloading, no matter which PHP version and XML lib is used. Downstream issue: FreshRSS/FreshRSS#8516 FreshRSS/FreshRSS#8710 1. https://www.php.net/manual/en/xml.constants.php#constant.xml-option-parse-huge 2. https://github.com/php/php-src/blob/90744ec52a50e0eacab47d5a51d82c1b26607b76/ext/xml/xml.c#L1116 3. https://wiki.php.net/rfc/xml_option_parse_huge Signed-off-by: Kidd Lee <[email protected]>
…huge feed (#977) PHP 8.4.0 introduced a new option[1], which makes it behave differently. > XML_OPTION_PARSE_HUGE (int) > Available as of PHP 8.4.0. When libxml2 < 2.7.0 is used (e.g. on PHP 7.x), this option is enabled by default and cannot be disabled. The default value of this new option is `0`[2]. And this option is only effective when `libxml2` is used. `libexpat` totally ignores it[3]. This patch sets this option to `1`, the old default value, when this option is defined. So everything is consistent. Yes, this brings more risks of potential DoS attack, but it should be defended somewhere else. Because the whole XML string is already downloaded into the memory when parsing, bars could be placed during downloading, no matter which PHP version and XML lib is used. Downstream issue: FreshRSS/FreshRSS#8516 FreshRSS/FreshRSS#8710 1. https://www.php.net/manual/en/xml.constants.php#constant.xml-option-parse-huge 2. https://github.com/php/php-src/blob/90744ec52a50e0eacab47d5a51d82c1b26607b76/ext/xml/xml.c#L1116 3. https://wiki.php.net/rfc/xml_option_parse_huge Signed-off-by: Kidd Lee <[email protected]>
* #8710 * simplepie/simplepie#977 Fix #8516 Co-authored-by: Kidd Lee <[email protected]>
After upgrade debian-based image from
freshrss:1.27.0tofreshrss:1.28.1, feed projectzerohttps://projectzero.google/feed.xmlstart failing to update, the log sayshttps://projectzero.google/feed.xml is invalid XML, likely due to invalid characters. XML error: No memory at line 1250, column 2167 [https://projectzero.google/feed.xml].According to the PHP doc[1]:
There is a new option
XML_OPTION_PARSE_HUGEafter PHP 8.4.0. And indeed there is an upgrade to PHP 8.4 between 1.27.0 and 1.28.1 in debian-based docker image. And the new default value isfalse[2].Set this option to
1fixed the problem for me.This should Closes #8516
why alpine-based docker image is not affected, my wild guess is it do not use
libxml2.