Fix use-after-free when a recursive extension proc rescues, skips or resets - #407
Merged
Merged
Conversation
…resets A recursive extension proc that rescued an error from the unpacker, called Unpacker#skip or called Unpacker#reset dropped stack.depth below the enclosing containers. Those containers were no longer GC-marked while the proc ran, so they could be collected before the parser wrote to them. Track the innermost recursive barrier as a stack floor. Error handling and reset now return depth to the floor instead of 0, and skip stops at the barrier like read does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
byroot
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A recursive extension proc that rescued an error from the unpacker, called
Unpacker#skip, or calledUnpacker#resetcould dropstack.depthbelow the enclosing containers. Those containers were then no longer GC-marked while the proc ran, so they could be collected before the parser wrote to them after the proc returned. This follows up on #405, which fixed the depth underflow but left this window open.The unpacker now tracks the innermost recursive barrier as a stack floor. Error handling and reset rewind the depth to the floor instead of 0, and
skipstops at the barrier likereaddoes.Reproduction
With 1.8.5 the script crashes with a SIGSEGV. With this change it prints
no crash.🤖 Generated with Claude Code