Skip to content

simplepie: fix potential XML error: No memory when parsing huge feed - #8710

Closed
LeeXiaolan wants to merge 1 commit into
FreshRSS:edgefrom
LeeXiaolan:kidd/main
Closed

LeeXiaolan wants to merge 1 commit into
FreshRSS:edgefrom
LeeXiaolan:kidd/main

Conversation

@LeeXiaolan

@LeeXiaolan LeeXiaolan commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

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

This should Closes #8516
why alpine-based docker image is not affected, my wild guess is it do not use libxml2.

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 Frenzie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Alkarex Alkarex added this to the 1.29.0 milestone Apr 22, 2026
@Alkarex

Alkarex commented Apr 22, 2026

Copy link
Copy Markdown
Member

Reference: https://wiki.php.net/rfc/xml_option_parse_huge

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 ?
I will then take care of the rest.

Personally, I would slightly prefer a if defined('XML_OPTION_PARSE_HUGE') {} but that is a detail.

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.

@Frenzie

Frenzie commented Apr 22, 2026

Copy link
Copy Markdown
Member

It's a pity that it's either a rather small limit or no limit at all.

@LeeXiaolan

Copy link
Copy Markdown
Contributor Author

Could you please send the same PR to https://github.com/simplepie/simplepie ?
I will then take care of the rest.

I just started a two-week-vacation, I will do it after back.

so it would be nice to improve how we handle this condition

It seems Parser does not take any configurations so far, and I am not familiar with its design pattern, so any suggestion?

@Alkarex Alkarex modified the milestones: 1.29.0, 1.30.0 May 3, 2026
LeeXiaolan added a commit to LeeXiaolan/simplepie that referenced this pull request May 22, 2026
…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]>
LeeXiaolan added a commit to LeeXiaolan/simplepie that referenced this pull request May 25, 2026
…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]>
LeeXiaolan added a commit to LeeXiaolan/simplepie that referenced this pull request May 26, 2026
…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]>
jtojnar pushed a commit to simplepie/simplepie that referenced this pull request May 26, 2026
…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]>
@LeeXiaolan LeeXiaolan closed this May 26, 2026
@Alkarex

Alkarex commented May 26, 2026

Copy link
Copy Markdown
Member

Alkarex added a commit that referenced this pull request May 26, 2026
@Alkarex

Alkarex commented May 26, 2026

Copy link
Copy Markdown
Member

Alkarex pushed a commit that referenced this pull request May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feed problem] projectzero.google XML error: No memory at line ...

3 participants