Skip to content

Revert "Fix #1176 JSON Decoder and Encoder limit disagreement (#1242)" #1306

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

Merged
merged 1 commit into from
May 23, 2025

Conversation

jmschonfeld
Copy link
Contributor

In addition to the known issue where this new test crashes on Windows, I've also found that the test crashes on non-macOS Apple platforms (confirmed a crash on iOS, tvOS, and watchOS which CI does not test on this repo). In those cases, the test is crashing because we're hitting the stack guard in a deeply nested call - I think this test ends up hitting the stack limit. For some reason it doesn't seem to occur on macOS or Linux as reported in the original PR (and I confirmed it passed on macOS) so perhaps there's a difference in the stack limits between these environments.

Noting that while the test passes on macOS + Linux it fails on all other platforms, I'm posting this revert to roll back the change until we can further investigate a better way to test this code path that avoids hitting the stack guard.

cc @jevonmao

@jmschonfeld jmschonfeld requested review from kperryua and itingliu May 20, 2025 23:22
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

I dug a bit deeper to see if I could resolve this quickly rather than reverting, and found out:

  • iOS/tvOS/watchOS and Windows platforms have a significantly smaller default stack size than Linux and macOS (Linux/macOS default to around 8mb whereas iOS/tvOS/watchOS/Windows default to around 1MB). I believe this is why the pass test is crashing on those platforms - a recursion limit of 512 is too high to prevent hitting the stack guard. We likely need to adjust the recursion limit on a per-platform basis to allow 512 on macOS/Linux (to reduce any compatibility fallout) but lower to something like 256 on platforms with smaller default stack sizes
  • After attempting to perform the above mitigation myself and creating a new pass test that contains 400 nested arrays rather than 512, the pass test still crashes on those platforms. In fact, setting the recursion limit to just 5 still allows the pass test to crash when the input data has 400 nested arrays. It seemed to decode successfully, but hit the stack guard on iOS while re-encoding it. It seems that 400 might be too high of a recursion limit, however the bigger problem here is that the recursion limit doesn't seem to be respected during encoding (but a cursory glance at the code seems to suggest perhaps it should be). I'm going to revert this for now and will add more information to Windows/iOS Crash During Deep JSON Encoding/Decoding #1304 to track this issue so that it can be resolved before re-merging the original change

@jmschonfeld jmschonfeld merged commit 1eed9aa into swiftlang:main May 23, 2025
15 checks passed
@jmschonfeld jmschonfeld deleted the revert-json-depth branch May 23, 2025 16:48
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.

2 participants