Skip to content

[streams] Bound user stream wrapper recursion with a depth counter - #262

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/userspace-stream-recursion-guard-84
Open

[streams] Bound user stream wrapper recursion with a depth counter#262
iliaal wants to merge 1 commit into
PHP-8.4from
fix/userspace-stream-recursion-guard-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

The userspace stream wrapper recursion guard only compared the filename being opened against the currently open one, so a wrapper whose stream_open() opens a different path at every level (for example an incrementing counter embedded in the URL) recursed without bound and exhausted the C stack. This adds a per-request nesting depth counter shared by user_wrapper_opener() and user_wrapper_opendir() that rejects opens beyond 64 nested levels with the existing "infinite recursion prevented" error, keeping the filename comparison for direct self-recursion. Sibling audit found no other entry point that nests user-wrapper opens through fopen/opendir.

The userspace wrapper recursion guard only compared the filename being
opened against the currently open one, so a wrapper whose stream_open()
opens a different path at every level (e.g. an incrementing counter in
the URL) recursed without bound and exhausted the C stack. Add a
per-request nesting depth counter shared by user_wrapper_opener() and
user_wrapper_opendir(), rejecting opens beyond 64 nested levels with the
existing "infinite recursion prevented" error. Sibling audit: no other
entry point nests user-wrapper opens; stat/unlink/rename/mkdir/rmdir and
metadata handlers do not recurse through fopen/opendir.
@iliaal iliaal closed this Aug 24, 2026
@iliaal iliaal reopened this Aug 24, 2026
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.

1 participant