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

[SR-7743] JSONDecoder.decode<A>(_:from:) EXC_BAD_ACCESS #50283

Closed
swift-ci opened this issue May 22, 2018 · 15 comments
Closed

[SR-7743] JSONDecoder.decode<A>(_:from:) EXC_BAD_ACCESS #50283

swift-ci opened this issue May 22, 2018 · 15 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7743
Radar rdar://problem/39866044
Original Reporter garricn (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @mikeash
Priority Medium

md5: b32e244200b8433066d03e525109da3c

is duplicated by:

  • SR-8481 Crash in storeEnumTagSinglePayload

relates to:

  • SR-8481 Crash in storeEnumTagSinglePayload

Issue Description:

I'm seeing the following two crashes (portions redacated):

EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x000000010b814000
Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x107892600 swift_storeEnumTagSinglePayload + 36
1  libswiftFoundation.dylib       0x107b20fb0 _JSONDecoder.unbox<A>(_:as:) + 89864
2  libswiftFoundation.dylib       0x107b1fd90 JSONDecoder.decode<A>(_:from:) + 85224
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000000010de68000
Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x10737a420 swift_getEnumCaseSinglePayload + 36
1  libswiftFoundation.dylib       0x107607dc4 JSONDecoder.decode<A>(_:from:) + 85276

For each crash, the last line of my code that is being run is the same; its the following try:

do {
  // where T is Decodable and implements custom decoding
  try JSONDecoder().decode(T.self, from: data)
} catch {
  print(error)
}

Based on my crash reports, it appears the crash stems from inside the swift decoding process.

Is this a bug in Swift? If not, what is the crash trying to tell me? What hints can I get from "swift_storeEnumTagSinglePayload" and "swift_getEnumCaseSinglePayload"?

Any help would be greatly appreciated. Thank you!

Link to related Twitter thread: https://twitter.com/garricn/status/999053291689361409

@jckarter
Copy link
Member

This looks like a compiler or runtime bug. What compiler version are you using? Can you attach your project? Does the crash happen in optimized, unoptimized, or both builds?

@swift-ci
Copy link
Collaborator Author

Comment by Garric Nahapetian (JIRA)

Thank you so much for replying. Xcode 9.3, Swift 4.1, and optimized. Unfortunately, I cannot attach the project. Let me know if there is anything else I can provide. I am not able to repo locally. I am seeing this crash via crashlytics.

I've attached the stack trace for one instance.

swift-crash.txt

@jckarter
Copy link
Member

Does it also reproduce if you disable optimization, like in a debug build?

@swift-ci
Copy link
Collaborator Author

Comment by Garric Nahapetian (JIRA)

I am not able to reproduce it locally. Also, I tried running it locally with optimization disabled was not able to reproduce. I will try to put an unoptimized build out into the wild and see if the crash still occurs. Thank you.

@jckarter
Copy link
Member

cc aschwaighofer@apple.com (JIRA User)

Thanks for checking! You might be able to narrow down the problem by selectively disabling optimization on the part of your program that's crashing, which might help you find a smaller test case that you would be able to share with us for debugging purposes. You can use the @_optimize(none) attribute on a function to disable optimization for a specific function.

@swift-ci
Copy link
Collaborator Author

Comment by Sebastian Skuse (JIRA)

Hi,

We're seeing the same issue as above being reported in Crashlytics after compiling with Swift 4.1 / Xcode 9.3.

I've been unable to reproduce with debug builds, playgrounds or with optimisation switched on. All the crashes seem to occur as above - JSONDecoder attempts to unbox a custom object conforming to Codable and eventually crashes inside swift_getEnumCaseSinglePayload / swift_storeEnumTagSinglePayload.

A crashlog can be found here: https://gist.github.com/sebskuse/e3531fc49ef6b5162f6614b3e86f2708

@swift-ci
Copy link
Collaborator Author

Comment by Garric Nahapetian (JIRA)

I was able to put out a beta build with optimization disabled SWIFT_OPTIMIZATION_LEVEL = "-Onone" for the entire project, and the crash manifested. I've attached the stack trace (stack-trace-2.txt).

@mattneub
Copy link

mattneub commented Jun 8, 2018

Here is a tiny project that allow you to reproduce the crash.

https://github.com/stoyanmar/CodableTest

You will have to be using Xcode 9.3 or 9.4; the issue is gone in Xcode 10 beta 1.

Turning on Whole Module Optimization for Debug configuration avoids the crash.

@jckarter
Copy link
Member

Thanks @mattneub! I was helping Garric in the WWDC labs last week, and IIRC he said the crash in his case was still manifesting in Xcode 10 beta 1, so your crash might be a different issue we've since fixed.

@mattneub
Copy link

@jckarter For the github project I pointed to, even "regressing" to the legacy build system does not elicit the crash on Xcode 10 beta 1, so it may be well and truly fixed — and, as you say, may be unrelated to the actual issue the original bug was about. The crash I'm talking about is still a real bug in Xcode 9.3 and 9.4 but I guess there's no point separating it out, as there will presumably never be a further update along that branch.

@swift-ci
Copy link
Collaborator Author

Comment by Deepak (JIRA)

We are seeing the same issue with Xcode 9.4 and Swift 4.1

@mikeash
Copy link
Contributor

mikeash commented Aug 30, 2018

This has been fixed in this PR: #17880

@swift-ci
Copy link
Collaborator Author

Comment by Garric Nahapetian (JIRA)

Thank you, @mikeash!

@mikeash
Copy link
Contributor

mikeash commented Aug 30, 2018

Glad to be of service!

@swift-ci
Copy link
Collaborator Author

Comment by Amber Katyal (JIRA)

Issue still reproducible. Temporarily fixed by enabling whoe module optimization. Changed data type from Int? to Float?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants