Skip to content

[3.0] Avoid JIT stack exhaustion in long code blocks - #9904

Open
mattago93 wants to merge 1 commit into
SimpleMachines:release-3.0from
mattago93:fix-9886-large-code-block-jit
Open

mattago93 wants to merge 1 commit into
SimpleMachines:release-3.0from
mattago93:fix-9886-large-code-block-jit

Conversation

@mattago93

Copy link
Copy Markdown

Fixes #9886, where long [code] blocks cause preg_split() to fail with PREG_JIT_STACKLIMIT_ERROR.

The existing recursive regular expression has been replaced with a simpler lazy multiline pattern in both Parser::sanitize() and Parser::getEditableString().

The new pattern avoids excessive PCRE JIT stack usage while preserving the existing code block matching behavior in the tested cases.

Verification:

  • Reproduced the original JIT stack exhaustion on PHP 8.4.24.
  • Confirmed the replacement handles code blocks containing up to 250,000 characters.
  • Compared 10,023 input cases, including multiline, adjacent, nested and malformed BBCode sequences, with no differences observed.
  • Added two PHPUnit regression tests covering sanitization and editable text conversion.
  • The complete PHPUnit suite and Composer lint have not been run locally.

Issues References (Fixes|Related|Closes)

Fixes #9886

Use a lazy multiline match in code block protection instead of the
recursive expression. The old pattern caused preg_split() to fail on
long code blocks in sanitize() and getEditableString().

Add focused regression tests for both methods.

Fixes SimpleMachines#9886

Signed-off-by: Mattia Agostini <agostini.19@gmail.com>
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.0]: [code] replacement regex exhausts the JIT stack limit

2 participants