Skip to content

lexbor: Fix the allocation and move sizes of lexbor_array_obj_t - #25431

Merged
kocsismate merged 1 commit into
php:masterfrom
nicolas-grekas:lexbor-array-obj
Nov 16, 2026
Merged

kocsismate merged 1 commit into
php:masterfrom
nicolas-grekas:lexbor-array-obj

Conversation

@nicolas-grekas

@nicolas-grekas nicolas-grekas commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Split from #23949.

lexbor_array_obj_t allocates 8 times the memory it uses. ext/dom uses such an array as its work list when it converts the parsed tree to libxml2. The waste grows with the number of sibling nodes. Parsing '<main>' . str_repeat('<i></i>', 100000) . '</main>' with Dom\HTMLDocument::createFromString() now peaks at 25.6MB instead of 52.4MB.

The fix is lexbor/lexbor@f4cbbcd, already merged upstream. This PR adds it as patch 0026.

gh25118.phpt relied on the oversized work list to reach its 32MB memory_limit during the conversion. I lowered the limit to 26M so that the test still fails there. It's now skipped when the Zend allocator is disabled, because the limit is then reached at another point. The test still crashes when the fix for GH-25118 is reverted. @devnexen please tell me if you prefer another way.

Comment thread NEWS Resolved

@kocsismate kocsismate 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.

Other than my question, LGTM

lexbor_array_obj_init() and lexbor_array_obj_expand() allocated 8 times
the memory they need on 64-bit platforms, and lexbor_array_obj_delete()
moved 8 times the bytes of the remaining entries. This is patch 0026,
merged upstream as lexbor/lexbor@f4cbbcd.

ext/dom uses such an array as its work list when it converts the parsed
tree to libxml2, so gh25118.phpt needs a lower memory_limit to still
fail during that conversion.
@kocsismate
kocsismate merged commit e2f6f22 into php:master Nov 16, 2026
18 checks passed
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.

3 participants