Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit recursion limits to avoid stack overflows #420

Merged
merged 3 commits into from
Oct 12, 2022

Conversation

juntyr
Copy link
Member

@juntyr juntyr commented Oct 9, 2022

Fixes #307 and the long-standing potential for stack overflows while serialising or deserialising.

Now, ron::Options is by default configured for a recursion limit of 128 (here recursion is very loosely defined). This limit can be adjusted or disabled.

This bug was first reported by @5225225 in #307 and later by oss-fuzz.

This PR also slightly extends the from_str fuzz target to check serialising as well.

  • I've included my change in CHANGELOG.md

@juntyr
Copy link
Member Author

juntyr commented Oct 9, 2022

@torkleyy Does this API change look good to you? If so, feel free to squash and merge.

I would be surprised if anyone is using such highly recursive data structures in the wild and would be affected by the default limit. Hence, this might be a v0.9 change?

@juntyr juntyr self-assigned this Oct 9, 2022
@juntyr juntyr requested a review from torkleyy October 9, 2022 10:56
@juntyr juntyr marked this pull request as ready for review October 9, 2022 10:57
@codecov-commenter
Copy link

Codecov Report

Base: 93.06% // Head: 87.19% // Decreases project coverage by -5.86% ⚠️

Coverage data is based on head (ab9f879) compared to base (0c32f8d).
Patch coverage: 56.52% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #420      +/-   ##
==========================================
- Coverage   93.06%   87.19%   -5.87%     
==========================================
  Files          56       57       +1     
  Lines        6618     7117     +499     
==========================================
+ Hits         6159     6206      +47     
- Misses        459      911     +452     
Impacted Files Coverage Δ
src/error.rs 33.33% <0.00%> (-9.29%) ⬇️
tests/307_stack_overflow.rs 100.00% <ø> (ø)
src/options.rs 43.28% <5.55%> (-16.72%) ⬇️
src/ser/mod.rs 75.18% <64.58%> (-20.42%) ⬇️
src/de/mod.rs 71.31% <68.75%> (-22.22%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@juntyr
Copy link
Member Author

juntyr commented Oct 9, 2022

Part of the codecov regression is spurious, part is expected. As I've spent the past few commits increasing codecov this is unfortunate, but I'll get to adding coverage for the stack overflow checks at some point :)

@juntyr juntyr changed the title 307 stack overflow Add explicit recursion limits to avoid stack overflows Oct 9, 2022
@juntyr
Copy link
Member Author

juntyr commented Oct 12, 2022

@torkleyy As you might be busy, I will merge this PR on Friday if you don’t object. While this change would break deeply nested structures, I think this can be dealt with by pushing the change to 0.9 instead of 0.8.1. Apart from a new error, the API update is a non-breaking change.

Copy link
Contributor

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

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

Yes limiting the recursion limit is certainly useful especially for untrusted inputs. 👍

@juntyr juntyr merged commit 562963f into ron-rs:master Oct 12, 2022
@juntyr juntyr deleted the 307-stack-overflow branch October 12, 2022 06:58
juntyr added a commit to juntyr/ron that referenced this pull request Aug 15, 2023
* Explicit recursion limit during deserializing

* Explicit recursion limit during serializing

* Added CHANGELOG entry
juntyr added a commit to juntyr/ron that referenced this pull request Aug 16, 2023
* Explicit recursion limit during deserializing

* Explicit recursion limit during serializing

* Added CHANGELOG entry
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.

Stack overflow when parsing deeply nested map
3 participants