Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cap unserialize recursion depth via unserialize_max_depth ini#414

Open
iliaal wants to merge 4 commits into
igbinary:masterigbinary/igbinary:masterfrom
iliaal:fix/unserialize-max-depthiliaal/igbinary:fix/unserialize-max-depthCopy head branch name to clipboard
Open

Cap unserialize recursion depth via unserialize_max_depth ini#414
iliaal wants to merge 4 commits into
igbinary:masterigbinary/igbinary:masterfrom
iliaal:fix/unserialize-max-depthiliaal/igbinary:fix/unserialize-max-depthCopy head branch name to clipboard

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented May 7, 2026

Cap recursion in igbinary_unserialize_zval at BG(unserialize_max_depth) (default 4096, 0 disables) on PHP 7.4+, hardcoded 4096 on 7.0-7.3. Without the cap, a deeply nested payload exhausts the C stack and segfaults the worker, reachable via session.serialize_handler=igbinary before userland code runs

Cap recursion in igbinary_unserialize_zval at BG(unserialize_max_depth)
(default 4096, 0 disables) on PHP 7.4+, hardcoded 4096 on 7.0-7.3.
Without the cap, a deeply nested payload exhausts the C stack and
segfaults the worker, reachable via session.serialize_handler=igbinary
before userland code runs.
@iliaal iliaal force-pushed the fix/unserialize-max-depth branch from 9a06f82 to 3d3f0c3 Compare May 7, 2026 13:11
Mark igbinary_unserialize_zval zend_always_inline so the per-zval
depth check folds into each callsite, restoring the pre-cap stack-
frame profile on the unserialize hot path. Reorder the guard to
short-circuit on the dynamic counter first and use ZEND_LONG_FMT
for the warning so the value isn't silently truncated to 32 bits
when zend_long is 64-bit and long is 32-bit (Windows x64).
Copy link
Copy Markdown
Member

@tricky tricky left a comment

Choose a reason for hiding this comment

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

Funnily enough the exact things I was going to comment on yesterday. :)

iliaal added 2 commits May 8, 2026 06:59
ZEND_LONG_FMT expands to "%" PRId64 / PRId32 from <inttypes.h>; older
PHP Windows builds didn't pull that header transitively, so the warning
in igbinary_unserialize_zval failed to compile with "missing ')' before
PRId64". Include inttypes.h directly. The depth-bomb test built a
250 KB payload with a 50000-iteration .= loop (O(n^2) in PHP), which
took longer than the 6h CI timeout under valgrind on PHP 8.0+. Build
the same payload via str_repeat with 5000 levels instead.
BG(unserialize_max_depth) is backed by ts_allocate_id-malloc'd thread storage
that basic_globals_ctor does not zero. On valgrind builds without
--enable-valgrind, the field carries malloc-origin taint and reading it
trips 'Conditional jump on uninitialised value' on every unserialize call.
zend_ini_long() reads the canonical INI hashtable entry, which has a
defined-storage path.

Caught by the GitHub Actions valgrind job on PHP 8.x.
@iliaal
Copy link
Copy Markdown
Author

iliaal commented May 8, 2026

After 8 tries finally a clean build 😮‍💨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.