Skip to content

[TSRM] Roll back id_count when resource type allocation fails - #291

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/tsrm-realloc-slot-hole-84
Open

[TSRM] Roll back id_count when resource type allocation fails#291
iliaal wants to merge 1 commit into
PHP-8.4from
fix/tsrm-realloc-slot-hole-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

ts_allocate_id() and ts_allocate_fast_id() bump id_count before growing resource_types_table or reserving fast-path space, so realloc failure or reservation exhaustion leaves id_count counting an uninitialized slot; allocations and per-thread setup then read that hole. Both roll id_count back under the mutex on either condition, restoring tsrm_reserved_pos on the fast path, keeping table, reservation and thread storage counts consistent. tsrm_update_active_threads() and allocate_new_resource() leave allocator returns unchecked (separate gap). No runtime repro (ZTS plus a failing realloc).

ts_allocate_id() and ts_allocate_fast_id() incremented id_count before
growing resource_types_table; on realloc failure (or exhausted fast
reservation space) they returned 0 while id_count still counted the new
slot, leaving an uninitialized hole that later allocations and thread
storage setup would read. Roll back id_count (and tsrm_reserved_pos for
the fast path) on all three failure paths so state stays consistent.
Sibling audit: tsrm_update_active_threads() and allocate_new_resource()
have unchecked allocator returns, which is an OOM-hardening gap outside
this slot-hole fix.
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