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-936] NSMutableData's hash() causes a segmentation fault on Linux #4577
Comments
Comment by Christian Rishøj (JIRA) A stack overflow appears to occur with Reproducible with the following minimal test case (using Swift 2.2 on Ubuntu 14.04): Welcome to Swift version 2.2-dev (LLVM 524cfeb800, Clang f66c5bb67b, Swift 870696170f). Type :help for assistance.
1> import Foundation
2> NSData().hash
$R0: Int = 0
3> NSMutableData().hash
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.) Backtrace snippet: 4> :bt 10
* thread #​1: tid = 18075, 0x00007ffff429dd7c libFoundation.so`static Foundation.=== infix (Swift.AnyObject.Type, Swift.AnyObject.Type) -> Swift.Bool + 12, name = 'repl_swift', stop reason = signal SIGSEGV: invalid address (fault address: 0x7fffff7feff8)
* frame #​0: 0x00007ffff429dd7c libFoundation.so`static Foundation.=== infix (Swift.AnyObject.Type, Swift.AnyObject.Type) -> Swift.Bool + 12
frame #​1: 0x00007ffff4119c47 libFoundation.so`Foundation.NSData._cfObject.getter : __ObjC.CFData + 39
frame #​2: 0x00007ffff411a051 libFoundation.so`Foundation.NSData.hash.getter : Swift.Int + 17
frame #​3: 0x00007ffff429b03a libFoundation.so`Foundation._CFSwiftGetHash (Swift.AnyObject) -> Swift.UInt + 58
frame #​4: 0x00007ffff429c50a libFoundation.so`@objc Foundation._CFSwiftGetHash (Swift.AnyObject) -> Swift.UInt + 26
frame #​5: 0x00007ffff411a05d libFoundation.so`Foundation.NSData.hash.getter : Swift.Int + 29
frame #​6: 0x00007ffff429b03a libFoundation.so`Foundation._CFSwiftGetHash (Swift.AnyObject) -> Swift.UInt + 58
frame #​7: 0x00007ffff429c50a libFoundation.so`@objc Foundation._CFSwiftGetHash (Swift.AnyObject) -> Swift.UInt + 26
frame #​8: 0x00007ffff411a05d libFoundation.so`Foundation.NSData.hash.getter : Swift.Int + 29
frame #​9: 0x00007ffff429b03a libFoundation.so`Foundation._CFSwiftGetHash (Swift.AnyObject) -> Swift.UInt + 58 |
I don't think this is related to SR-1547, as there's no error objects here. The key symptom of this bug is the endless mutual recursion between `_CFSwiftGetHash` and `NSData.hash.getter`. I've seen that same symptom in a larger program that used Foundation.Data, but only on Linux, not on macOS. The workaround in that case was to first check if the data object was zero-length and not request the hashValue unless it had at least one byte. |
The original issue seems to be fixed in 4.0.1-dev: {{$ swift -I /usr/lib/swift/clang/include The second problem, that there is a recursive call on NSMutableData's hash, still seems to exist: {{ 3> NSData().hash
|
Possible fix: #1669 |
Merged to `master` branch. |
Environment
Ubuntu 14.04, Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 24a0c3de75)
Reproduced on Ubuntu 16.04, Swift version 4.0.1-dev (LLVM 2dedb62a0b, Clang ab7472e733, Swift 7efb2d13a2)
Additional Detail from JIRA
md5: bf8cffe9642151374ef9e452574daaaf
relates to:
Issue Description:
The current implementation of NSData's hash() causes a segmentation fault on Linux.
Using the REPL on Mac:
on Linux:
The text was updated successfully, but these errors were encountered: