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-8219] Memory corruption of private enum property #50751

Closed
rnapier opened this issue Jul 10, 2018 · 5 comments
Closed

[SR-8219] Memory corruption of private enum property #50751

rnapier opened this issue Jul 10, 2018 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2

Comments

@rnapier
Copy link

rnapier commented Jul 10, 2018

Previous ID SR-8219
Radar rdar://problem/42039517
Original Reporter @rnapier
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 4.2 beta (Xcode 10b3)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, Miscompile
Assignee @aschwaighofer
Priority Medium

md5: f5386839f0fc18425de06594c88ac4ec

Issue Description:

Given the following code, a caller to init(...) from another module will often trigger the fatalError. The resulting credential will be .password with a garbage value (mostly a string of \0, with occasionally other values).

import Foundation

public final class DecryptorV3 {
    var buffer = Data() // Required
    var decryptorEngine: JSONDecoder? // Any class. This reproduces with a struct, but less often.
    private let credential: Credential // Required

    public init(encryptionKey: Data, hmacKey: Data) {
        credential = .keys(encryptionKey: encryptionKey, hmacKey: hmacKey)
        print("INIT WITH KEYS. credential=\(credential)") // Required; doesn't reproduce w/o evaluating credentials
        guard case .keys(_, _) = credential else { fatalError("CREDENTIALS ARE NOT KEYS: \(credential)") }
    }

    public func decrypt(data: Data) throws -> Data {
        return Data()
    }
}

/* This `private` is required to cause error */
private enum Credential {
    case password(String)
    case keys(encryptionKey: Data, hmacKey: Data)
}

A more complete example project is attached (minimized; this is not the full RNCryptor code). Run the unit test. The failure case is either the fatalError firing or a crash in DecryptorV3.deinit.

This failure is new in Xcode 10b3. See RNCryptor/RNCryptor#276.

@belkadan
Copy link
Contributor

@swift-ci create

@belkadan
Copy link
Contributor

@slavapestov, @rjmccall, this sounds like the kind of alignment issue we had way back with Objective-C classes. Could we have a similar problem with resilient layout?

@aschwaighofer
Copy link
Member

This was fixed by #17590

The test case no longer crashes with a recent swift-4.2-branch toolchain.

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Aug 4, 2018

@rnapier,
Could you verify if the problem is fixed and if so move the JIRA to "Closed"?
Thanks!
Anna

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Aug 28, 2018

@rnapier,

Could you please verify that the bug is resolved? We'd like to close this issue.

Thanks!
Anna

@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 regression swift 4.2
Projects
None yet
Development

No branches or pull requests

4 participants