Skip to content

[SR-7103] JSONDecoder with badly configured dateDecodingStrategy crashes with EXC_BAD_INSTRUCTION #49651

@swift-ci

Description

@swift-ci
Previous ID SR-7103
Radar None
Original Reporter robinwit (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.2 (9C40b)

macOS 10.13.3 (17D102)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 5d9a0d4666ce55f5174c4a2966a76b3c

Issue Description:

The following crashes in a Playground, and while debugging an app it takes down Xcode.

import Foundation

struct Wrapper: Codable {
    let objects: [MyObject]
}

struct MyObject: Codable {
    let date: Date
}

let decoder = JSONDecoder()
let data = "{\"date\": \"2018-03-01T20:14:00Z\"}".data(using: .utf8)

/*
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
let data = "{\"date\": \"2018-03-01T20:14:00\"}".data(using: .utf8) // this also crashes (note the missing 'Z')
*/

try! decoder.decode(MyObject.self, from: data!) // crash here

Result:

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

Expected:

I'd think that with the forced try, my program would just halt with the same error that I would get with do/catch, instead of crashing the compiler or Xcode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions