[php-src] PR #24516: ext/xml: Make Expat allocators fallible

From: Date: Wed, 21 Oct 2026 22:31:11 +0000
Subject: [php-src] PR #24516: ext/xml: Make Expat allocators fallible
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-39684@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/24516 Author: rmetzler Part of GH-24492. ext/xml built with --with-expat passes emalloc()/erealloc() to XML_ParserCreate_MM(). Since the hard memory limit was introduced (3584a98bda), a document that makes Expat allocate past memory_limit keeps getting memory until the hard limit is reached, and then the process exits with 137. With libxml2 the same input still produces the regular "Allowed memory size exhausted" fatal error. Expat handles allocation failures itself (XML_ERROR_NO_MEMORY), so this switches the two wrappers to the fallible allocator, as was done for libmagic in ext/fileinfo/libmagic/cdf.c. Expat then stops parsing, xml_parse() returns, and the queued OOM error is raised. A failed ferealloc() leaves the original block untouched, which is what Expat expects from realloc_fcn. Covered by the existing tests, which fail in an Expat build without this change: - ext/xml/tests/oom_xml_parse_ns.phpt - ext/xml/tests/gh14637.phpt No CI job builds ext/xml with Expat, so these only show up in distro builds. I can send a separate PR that adds --with-expat to one of the existing jobs. Tested with a minimal ZTS build (--disable-all --enable-xml --with-expat, Expat 2.9.0, Alpine 3.23) on PHP-8.4, PHP-8.5 and PHP-8.2: all ext/xml tests pass except xml003.phpt, which fails with Expat with or without this change (deprecation output from 8.4). On PHP-8.2 there are no failures. PHP-8.2 and PHP-8.3 have the same problem since they received the same security fix. The wrappers are identical there, so the patch should apply unchanged (verified on PHP-8.2) if you want it in those branches. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

« previous php.git-pulls (#39684) next »