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-5477] NSRegularExpression crashes when created with invalid pattern on Linux #3830

Closed
marcelofabri opened this issue Jul 17, 2017 · 3 comments

Comments

@marcelofabri
Copy link

Previous ID SR-5477
Radar None
Original Reporter @marcelofabri
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 3.1.1 (swift-3.1.1-RELEASE)
Target: x86_64-unknown-linux-gnu

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

md5: 816b2d9f20e8dab6ed677027e58c804b

duplicates:

  • SR-5557 Foundation crashes instead of throwing in case of invalid regular expression pattern

Issue Description:

This code results in a crash:

import Foundation
_ = try? NSRegularExpression(pattern: "(", options: [])
swift bug.swift 
0  swift            0x0000000003631948
1  swift            0x0000000003632086
2  libpthread.so.0  0x00007f05d80bb390
3  libFoundation.so 0x00007f05d1afa210 __HALT + 0
4  libFoundation.so 0x00007f05d1b0b6a5
5  libFoundation.so 0x00007f05d1b15cce CFDictionaryCreate + 270
6  libFoundation.so 0x00007f05d1c4762b _CFRegularExpressionCreate + 427
7  libFoundation.so 0x00007f05d1e2fe9b _TTSf4gs_n_n___TFC10Foundation19NSRegularExpressioncfzT7patternSS7optionsVS0_7Options_S0_ + 107
8  libFoundation.so 0x00007f05d1e2dd0d _TFC10Foundation19NSRegularExpressionCfzT7patternSS7optionsVS0_7Options_S0_ + 93
9  libFoundation.so 0x00007f05d84e80b5 _TFC10Foundation19NSRegularExpressionCfzT7patternSS7optionsVS0_7Options_S0_ + 107717637
10 swift            0x0000000000e200df
11 swift            0x0000000000e24132
12 swift            0x000000000048ae22
13 swift            0x000000000047f96e
14 swift            0x000000000043b0d7
15 libc.so.6        0x00007f05d6c26830 __libc_start_main + 240
16 swift            0x0000000000438519
Stack dump:
0.  Program arguments: /usr/bin/swift -frontend -interpret bug.swift -disable-objc-interop -color-diagnostics -module-name bug 
Illegal instruction

Stack trace from a real use case:

* thread #​1, name = 'SwiftLintPackag', stop reason = signal SIGILL: illegal instruction operand
  * frame #​0: 0x00007ffff6f48210 libFoundation.so`__HALT
    frame #​1: 0x00007ffff6f596a5 libFoundation.so`CFBasicHashAddValue + 229
    frame #​2: 0x00007ffff6f63cce libFoundation.so`CFDictionaryCreate + 270
    frame #​3: 0x00007ffff709562b libFoundation.so`_CFRegularExpressionCreate + 427
    frame #&#8203;4: 0x00007ffff727de9b libFoundation.so`function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of Foundation.NSRegularExpression.init (pattern : Swift.String, options : Foundation.NSRegularExpression.Options) throws -> Foundation.NSRegularExpression + 107
    frame #&#8203;5: 0x00007ffff727bd0d libFoundation.so`Foundation.NSRegularExpression.__allocating_init (pattern : Swift.String, options : Foundation.NSRegularExpression.Options) throws -> Foundation.NSRegularExpression + 93
    frame #&#8203;6: 0x000000000068d36f SwiftLintPackageTests.xctest`static NSRegularExpression.cached(pattern=<unavailable>, options=<unavailable>, self=<unavailable>, $error=<unavailable>) throws -> NSRegularExpression at NSRegularExpression+SwiftLint.swift:49
    frame #&#8203;7: 0x00000000008c736c SwiftLintPackageTests.xctest`RegexConfiguration.apply(configuration=<unavailable>, self=<unavailable>, $error=<unavailable>) throws -> () at RegexConfiguration.swift:62
    frame #&#8203;8: 0x000000000073bc49 SwiftLintPackageTests.xctest`CustomRulesConfiguration.apply(configuration=<unavailable>, self=<unavailable>, $error=<unavailable>) throws -> () at CustomRules.swift:38
    frame #&#8203;9: 0x000000000047de10 SwiftLintPackageTests.xctest`CustomRulesTests.testCustomRuleConfigurationIgnoreInvalidRules(self=<unavailable>, $error=<unavailable>) throws -> () at CustomRulesTests.swift:59
    frame #&#8203;10: 0x000000000044779a SwiftLintPackageTests.xctest`partial apply at LinuxMain.swift:0
    frame #&#8203;11: 0x0000000000421aa8 SwiftLintPackageTests.xctest`thunk at LinuxMain.swift:0
    frame #&#8203;12: 0x00000000004478b9 SwiftLintPackageTests.xctest`partial apply for thunk at LinuxMain.swift:0
    frame #&#8203;13: 0x00007ffff7f63462 libXCTest.so`partial apply forwarder for reabstraction thunk helper from @callee_owned (@in ()) -> (@out (), @error @owned Swift.Error) to @callee_owned () -> (@error @owned Swift.Error) + 50
    frame #&#8203;14: 0x00007ffff7f412c2 libXCTest.so`XCTest.((test in _3BE257A46ADB477C7BF2D39968B39F9D) <A where A: XCTest.XCTestCase> ((A) -> () throws -> ()) -> (XCTest.XCTestCase) throws -> ()).(closure #&#8203;1) + 82
    frame #&#8203;15: 0x00007ffff7f63290 libXCTest.so`partial apply forwarder for reabstraction thunk helper from @callee_owned (@owned XCTest.XCTestCase) -> (@error @owned Swift.Error) to @callee_owned (@in XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) + 64
    frame #&#8203;16: 0x00007ffff7f637ee libXCTest.so`partial apply forwarder for reabstraction thunk helper from @callee_owned (@owned XCTest.XCTestCase) -> (@error @owned Swift.Error) to @callee_owned (@in XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) with unmangled suffix ".111" + 14
    frame #&#8203;17: 0x00007ffff7f634d0 libXCTest.so`partial apply forwarder for reabstraction thunk helper from @callee_owned (@in XCTest.XCTestCase) -> (@out (), @error @owned Swift.Error) to @callee_owned (@owned XCTest.XCTestCase) -> (@error @owned Swift.Error) + 64
    frame #&#8203;18: 0x00007ffff7f40950 libXCTest.so`XCTest.XCTestCase.invokeTest () -> () + 112
    frame #&#8203;19: 0x00007ffff7f56599 libXCTest.so`function signature specialization <Arg[0] = Owned To Guaranteed> of XCTest.XCTestCase.perform (XCTest.XCTestRun) -> () + 313
    frame #&#8203;20: 0x00007ffff7f4081e libXCTest.so`XCTest.XCTestCase.perform (XCTest.XCTestRun) -> () + 14
    frame #&#8203;21: 0x00007ffff7f3fc94 libXCTest.so`XCTest.XCTest.run () -> () + 516
    frame #&#8203;22: 0x00007ffff7f56b0b libXCTest.so`function signature specialization <Arg[0] = Owned To Guaranteed> of XCTest.XCTestSuite.perform (XCTest.XCTestRun) -> () + 1067
    frame #&#8203;23: 0x00007ffff7f56dab libXCTest.so`function signature specialization <Arg[0] = Owned To Guaranteed> of XCTest.XCTestSuite.perform (XCTest.XCTestRun) -> () + 1739
    frame #&#8203;24: 0x00007ffff7f56dab libXCTest.so`function signature specialization <Arg[0] = Owned To Guaranteed> of XCTest.XCTestSuite.perform (XCTest.XCTestRun) -> () + 1739
    frame #&#8203;25: 0x00007ffff7f338f1 libXCTest.so`XCTest.XCTMain (Swift.Array<(testCaseClass : XCTest.XCTestCase.Type, allTests : Swift.Array<(Swift.String, (XCTest.XCTestCase) throws -> ())>)>) -> Swift.Never + 4081
    frame #&#8203;26: 0x00000000004215ed SwiftLintPackageTests.xctest`main at LinuxMain.swift:479
    frame #&#8203;27: 0x00007ffff5a30830 libc.so.6`__libc_start_main + 240
    frame #&#8203;28: 0x0000000000420b99 SwiftLintPackageTests.xctest`_start + 41
@BenchR267
Copy link
Member

I have the same issue with the Swift 4.0 Development toolchain built on 4th of August.

However I saw that it's working on my virtual machine that is running Ubuntu 16.04 but it fails on the Ubuntu 14.04 machine that travis-ci.org is running.

I tried the pattern "[", but that shouldn't make a difference.

@BenchR267
Copy link
Member

Fixed in Swift 4.0 toolchain (built 15th of August) ✅

@marcelofabri
Copy link
Author

#1164

@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

2 participants