Add stack overflow crash protection, error out instead - #348
Open
lfittl wants to merge 3 commits into
Open
Conversation
This makes libpg_query return the standard "stack depth limit exceeded" error that Postgres also shows for overly deep queries, instead of crashing when stack depth gets exceeded. This error is triggered by appropriately placed calls to the Postgres check_stack_depth() function, and goes together with initializing the stack base and depth in pg_query_init. The maximum stack depth is handled similar to Postgres max_stack_depth variable, defaulting to 100 kB, and auto-sized up to 2MB. Because we may be called in threads with varying stack sizes, and from different host program locations, the allowed stack depth is recalculated for each call to libpg_query. Per multiple reports from OSS-Fuzz.
Member
|
Looks like there's a memory leak |
Member
Author
Yep, that was in Protobuf C++ specifically. Fixed! |
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.
This makes libpg_query return the standard "stack depth limit exceeded" error that Postgres also shows for overly deep queries, instead of crashing when stack depth gets exceeded. This error is triggered by appropriately placed calls to the Postgres check_stack_depth() function, and goes together with initializing the stack base and depth in pg_query_init.
The maximum stack depth is handled similar to Postgres max_stack_depth variable, defaulting to 100 kB, and auto-sized up to 2MB. Because we may be called in threads with varying stack sizes, and from different host program locations, the allowed stack depth is recalculated for each call to libpg_query.
Per multiple reports from OSS-Fuzz.
Follow-ups
protobuf_c_message_unpackcan run into similar issues, but since its a vendored library its not exactly sure how we should deal with it (possibly have a set of patches on top of it, and automate the vendoring?)