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-1547] NSData causes segmentation fault #4351

Closed
swift-ci opened this issue May 17, 2016 · 6 comments
Closed

[SR-1547] NSData causes segmentation fault #4351

swift-ci opened this issue May 17, 2016 · 6 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1547
Radar None
Original Reporter devgg (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Ubuntu 14.04
Swift version 3.0-dev (LLVM dffa09ffd8, Clang 1e6cba3ce3, Swift d2aee43220)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 3
Component/s Foundation
Labels Bug, Linux
Assignee mattrajca (JIRA)
Priority Medium

md5: bf2015ec5d9255dbcda105e2324bcc6f

is duplicated by:

  • SR-3490 String(contentsOfFile:encoding:) crashes when file is inaccessible

relates to:

  • SR-585 Segfault on Linux in code using "catch let error as NSError"
  • SR-936 NSMutableData's hash() causes a segmentation fault on Linux

Issue Description:

I discovered a bug probably related to SR-936.

import Foundation

do {
    let data = try NSData(contentsOfFile: "does not exist", options: [])
} catch {
    print(error)
}

I can include further info if necessary. But since I am new to swift I did not quite now how to add stacktrace, etc.

@swift-ci
Copy link
Contributor Author

Comment by Sergej Jaskiewicz (JIRA)

Still observe this issue in the release — even for existing files.

@swift-ci
Copy link
Contributor Author

Comment by Mark Woollard (JIRA)

I've done a bit of debugging on this, the crash is occurring in print(error) rather than NSData(..). Failure is at line 229 as below.

* thread #​1: tid = 6673, 0x00007ffff7c2298c libswiftCore.so`swift::ValueWitnessFlags::getAlignmentMask(this=0x0000000000000090) const + 12 at Metadata.h:229, name = 'TestFoundation', stop reason = signal SIGSEGV: invalid address (fault address: 0x90)
    frame #​0: 0x00007ffff7c2298c libswiftCore.so`swift::ValueWitnessFlags::getAlignmentMask(this=0x0000000000000090) const + 12 at Metadata.h:229
   226    /// For example, if the type needs to be 8-byte aligned, the
   227    /// appropriate alignment mask should be 0x7.
   228    size_t getAlignmentMask() const {
-> 229      return (Data & AlignmentMask);
   230    }
   231    constexpr ValueWitnessFlags withAlignmentMask(size_t alignMask) const {
   232      return ValueWitnessFlags((Data & ~AlignmentMask) | alignMask);
(lldb) bt
* thread #​1: tid = 6673, 0x00007ffff7c2298c libswiftCore.so`swift::ValueWitnessFlags::getAlignmentMask(this=0x0000000000000090) const + 12 at Metadata.h:229, name = 'TestFoundation', stop reason = signal SIGSEGV: invalid address (fault address: 0x90)
  * frame #​0: 0x00007ffff7c2298c libswiftCore.so`swift::ValueWitnessFlags::getAlignmentMask(this=0x0000000000000090) const + 12 at Metadata.h:229
    frame #​1: 0x00007ffff7c2296c libswiftCore.so`swift::ValueWitnessTable::getAlignmentMask(this=0x0000000000000000) const + 28 at Metadata.h:731
    frame #​2: 0x00007ffff7c228e6 libswiftCore.so`swift::SwiftError::getValue(this=0x0000000000aefa60) const + 102 at ErrorObject.h:119
    frame #​3: 0x00007ffff7c4c56d libswiftCore.so`swift_getErrorValue(errorObject=0x0000000000aefa60, scratch=0x00007fffffffcf18, out=0x00007fffffffcf00) + 29 at ErrorObjectNative.cpp:106
    frame #​4: 0x00000000004954bd TestFoundation`TestNSData.test_sr1547(self=0x0000000000a65720) -> () + 301 at TestNSData.swift:101

Am happy to take a further look at this to try and get to the bottom but am new to the Swift project so may need a bit of guidance !

@swift-ci
Copy link
Contributor Author

Comment by Mark Woollard (JIRA)

Some further info - this seems to be nothing specifically to do with NSData but with throw/catching of NSError. The following code fails at the same point:

do {
    throw NSError(domain: NSPOSIXErrorDomain, code: Int(123), userInfo: nil)
} catch {
    print(error)
}

@swift-ci
Copy link
Contributor Author

Comment by Mark Woollard (JIRA)

Adding SR-585 as related issue since this appears to be the actual issue and is not specific to NSData. May be worth closing SR-1547 but will let others make that call.

@swift-ci
Copy link
Contributor Author

Comment by Matt Rajca (JIRA)

Looks like SR-585 fixed this. I added a test for this as well: #999

@swift-ci
Copy link
Contributor Author

Comment by Matt Rajca (JIRA)

Fixed, +test: #999

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant