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

Crash on emoji as typealias with 0.14.0 #1006

Closed
mknabbe opened this issue Dec 19, 2016 · 15 comments
Closed

Crash on emoji as typealias with 0.14.0 #1006

mknabbe opened this issue Dec 19, 2016 · 15 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@mknabbe
Copy link
Contributor

mknabbe commented Dec 19, 2016

Swiftlint 0.14.0 crashes when run as build phase in Xcode 8.2 (8C38) while trying to parse following statement:
public typealias 🔳 = QRCode

/Users/XXXXX/Library/Developer/Xcode/DerivedData/XXXXXX-aqobyostblawgtbajeamvisokbcm/Build/Intermediates/CodeCoverage/Intermediates/XXXXXX.build/Debug-appletvsimulator/XXXXXX.build/Script-5BEA03541CCE131F008B1777.sh: line 6: 16251 Illegal instruction: 4 swiftlint
Command /bin/sh failed with exit code 132

@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Dec 19, 2016
@jpsim
Copy link
Collaborator

jpsim commented Dec 19, 2016

That's a fun one 😄 . Thanks for reporting! Although I can't reproduce this...

$ echo "public typealias 🔳 = QRCode" | swiftlint lint --use-stdin
Done linting! Found 0 violations, 0 serious in 1 file.

What does your configuration look like? Are you enabling any opt-in rules? Are you sure it crashes with just the sample you've provided, or does that string crash with a rule for text later in the file?

@marcelofabri
Copy link
Collaborator

I was able to reproduce the crash by adding this example on nonTriggeringExamples and running the tests:

Test Case '-[SwiftLintFrameworkTests.RulesTests testTypeName]' started.
fatal error: unexpectedly found nil while unwrapping an Optional value
2016-12-19 18:51:24.140399 xctest[2255:2159887] fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0    libswiftCore.dylib                 0x0000000105c55ce0 swift_reportError + 132
1    libswiftCore.dylib                 0x0000000105c73090 _swift_stdlib_reportFatalError + 61
2    libswiftCore.dylib                 0x0000000105a690c0 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 355
3    libswiftCore.dylib                 0x0000000105be5230 partial apply for (_fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x0000000105a690c0 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 355
5    libswiftCore.dylib                 0x0000000105b9d3f0 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never + 96
6    SourceKittenFramework              0x00000001057b6880 NSString.CacheContainer.(lineAndCharacter(forByteOffset : Int) -> (line : Int, character : Int)?).(closure #2) + 1546
7    SourceKittenFramework              0x00000001057b6480 thunk + 56
8    SourceKittenFramework              0x00000001057c4830 partial apply for thunk + 89
9    libswiftCore.dylib                 0x0000000105a685a0 Optional.map<A> ((A) throws -> A1) throws -> A1? + 363
10   SourceKittenFramework              0x00000001057b6530 NSString.CacheContainer.lineAndCharacter(forByteOffset : Int) -> (line : Int, character : Int)? + 597
11   SourceKittenFramework              0x00000001057b74b0 NSString.lineAndCharacter(forByteOffset : Int) -> (line : Int, character : Int)? + 61
12   SwiftLintFramework                 0x0000000105432f20 Location.init(file : File, byteOffset : Int) -> Location + 297
13   SwiftLintFramework                 0x00000001054a1900 TypeNameRule.validateName(name : String, dictionary : [String : SourceKitRepresentable], file : File, offset : Int) -> [StyleViolation] + 1167
14   SwiftLintFramework                 0x00000001054a3620 TypeNameRule.(validateTypeAliasesAndAssociatedTypes(File) -> [StyleViolation]).(closure #1) + 1742
15   SwiftLintFramework                 0x00000001054a56f0 partial apply for TypeNameRule.(validateTypeAliasesAndAssociatedTypes(File) -> [StyleViolation]).(closure #1) + 302
16   SwiftLintFramework                 0x00000001054a3ee0 thunk + 65
17   SwiftLintFramework                 0x00000001054a5870 partial apply for thunk + 89
18   libswiftCore.dylib                 0x0000000105b1c8a0 Sequence.flatMap<A where ...> ((A.Iterator.Element) throws -> A1) throws -> [A1.Iterator.Element] + 639
19   SwiftLintFramework                 0x00000001054a0d60 TypeNameRule.validateTypeAliasesAndAssociatedTypes(File) -> [StyleViolation] + 648
20   SwiftLintFramework                 0x00000001054a0a90 TypeNameRule.validateFile(File) -> [StyleViolation] + 243
21   SwiftLintFramework                 0x00000001054a4a00 protocol witness for Rule.validateFile(File) -> [StyleViolation] in conformance TypeNameRule + 259
22   SwiftLintFramework                 0x0000000105374e50 Linter.(getStyleViolations(Bool) -> ([StyleViolation], [(id : String, time : Double)])).(closure #1) + 912
23   SwiftLintFramework                 0x0000000105376dd0 thunk + 42
24   SwiftLintFramework                 0x00000001053780d0 partial apply for thunk + 89
25   libswiftCore.dylib                 0x0000000105b1c8a0 Sequence.flatMap<A where ...> ((A.Iterator.Element) throws -> A1) throws -> [A1.Iterator.Element] + 639
26   SwiftLintFramework                 0x0000000105374b30 Linter.getStyleViolations(Bool) -> ([StyleViolation], [(id : String, time : Double)]) + 558
27   SwiftLintFramework                 0x0000000105374ad0 Linter.styleViolations.getter + 63
28   SwiftLintFrameworkTests            0x00000001051d7480 violations(String, config : Configuration) -> [StyleViolation] + 1189
29   SwiftLintFrameworkTests            0x00000001051e2140 XCTestCase.verifyExamples(triggers : [String], nonTriggers : [String], configuration : Configuration) -> () + 1043
30   SwiftLintFrameworkTests            0x00000001051e0040 XCTestCase.verifyRule(RuleDescription, ruleConfiguration : Any?, commentDoesntViolate : Bool, stringDoesntViolate : Bool, skipCommentTests : Bool, skipStringTests : Bool, testMultiByteOffsets : Bool) -> () + 1891
31   SwiftLintFrameworkTests            0x000000010520ea80 RulesTests.testTypeName() -> () + 686
32   SwiftLintFrameworkTests            0x000000010520ed50 @objc RulesTests.testTypeName() -> () + 34
33   CoreFoundation                     0x00007fff9a86e360 __invoking___ + 140
34   CoreFoundation                     0x00007fff9a86e150 -[NSInvocation invoke] + 289
35   XCTest                             0x00000001000ac99d __24-[XCTestCase invokeTest]_block_invoke_2 + 481
36   XCTest                             0x00000001000e6b7e -[XCTestContext performInScope:] + 190
37   XCTest                             0x00000001000ac88b -[XCTestCase invokeTest] + 255
38   XCTest                             0x00000001000acfda -[XCTestCase performTest:] + 457
39   XCTest                             0x00000001000aa0c1 -[XCTestSuite performTest:] + 491
40   XCTest                             0x00000001000aa0c1 -[XCTestSuite performTest:] + 491
41   XCTest                             0x00000001000aa0c1 -[XCTestSuite performTest:] + 491
42   XCTest                             0x0000000100096c95 __25-[XCTestDriver _runSuite]_block_invoke + 51
43   XCTest                             0x00000001000bec21 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 602
44   XCTest                             0x00000001000969a7 -[XCTestDriver _runSuite] + 438
45   XCTest                             0x0000000100097655 -[XCTestDriver _checkForTestManager] + 612
46   XCTest                             0x00000001000e7e39 _XCTestMain + 628
47   xctest                             0x000000010000174b <unavailable> + 0
48   libdyld.dylib                      0x00007fffafdc9254 start + 1

@marcelofabri
Copy link
Collaborator

It seems that samePosition(in: content.utf16) is returning nil.

@marcelofabri
Copy link
Collaborator

marcelofabri commented Dec 19, 2016

Replacing lineAndCharacter(forByteOffset: in SourceKitten with this implementation solves the crash.

func lineAndCharacter(forByteOffset offset: Int) -> (line: Int, character: Int)? {
    let characterOffset = location(fromByteOffset: offset)
    return lineAndCharacter(forCharacterOffset: characterOffset)
}

All tests in SourceKitten pass, but I had to change OverriddenSuperCallRule.swift and ProhibitedSuperRule.swift so the markers in triggeringExamples would be after the { (they are before now). So I'm not 100% sure this is a correct change 😅

@jpsim
Copy link
Collaborator

jpsim commented Dec 19, 2016

Sounds like there's a bug somewhere in SourceKitten, whether it's in lineAndCharacter(forByteOffset:), location(fromByteOffset:) or lineAndCharacter(forCharacterOffset:). 😬

@marcelofabri
Copy link
Collaborator

It's in lineAndCharacter(forByteOffset:) 😅

@marcelofabri
Copy link
Collaborator

marcelofabri commented Dec 19, 2016

@marcelofabri
Copy link
Collaborator

Or were you referring to the +1 offset after changing the implementation? 🤔

@jpsim
Copy link
Collaborator

jpsim commented Dec 19, 2016

All of it. There's a bug now with lineAndCharacter(forByteOffset:) (as evidenced by this crash) and there's a bug in either location(fromByteOffset:), lineAndCharacter(forCharacterOffset:) or OverriddenSuperCall/ProhibitedSuper (as evidenced by the changed offset).

@marcelofabri
Copy link
Collaborator

I have no clue why only these tests are failing. I thought it could be because of \t (and maybe \n), but even after removing them I still get the failures 😭 (and the same behavior with the old implementation)

@mknabbe
Copy link
Contributor Author

mknabbe commented Dec 20, 2016

I don't know if it's still relevant. Here's my configuration.

disabled_rules: # rule identifiers to exclude from running
  - valid_docs
  - variable_name
opt_in_rules: # some rules are only opt-in
  - empty_count
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Pods

line_length: 150
type_body_length: 500

@marcelofabri marcelofabri added repro-needed Issues that cannot be reproduced or miss proper descriptive examples. and removed repro-needed Issues that cannot be reproduced or miss proper descriptive examples. labels Dec 23, 2016
@marcelofabri
Copy link
Collaborator

Another example of this crash: #1068 (comment)

@SDGGiesbrecht
Copy link
Contributor

Some possibly related debugging occurred in #1292 beginning with this comment.

@Coeur
Copy link

Coeur commented May 13, 2017

@SDGGiesbrecht I don't think it's the same thing. For #1006, the fix is said to be in this pull request: jpsim/SourceKitten#358

@jpsim
Copy link
Collaborator

jpsim commented May 19, 2017

Fixed in #1535.

@jpsim jpsim closed this as completed May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

5 participants