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

Out of range exception in AttributesRule #1105

Closed
jpsim opened this issue Jan 1, 2017 · 2 comments
Closed

Out of range exception in AttributesRule #1105

jpsim opened this issue Jan 1, 2017 · 2 comments
Labels
bug Unexpected and reproducible misbehavior.

Comments

@jpsim
Copy link
Collaborator

jpsim commented Jan 1, 2017

When running on test/Interpreter/SDK/objc_mangling.swift from Swift's source.

2017-01-01 11:20:28.001296 swiftlint[1964:2493303] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fffabebde7b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fffc0aa3cad objc_exception_throw + 48
    2   CoreFoundation                      0x00007fffabf3c99d +[NSException raise:format:] + 205
    3   Foundation                          0x00007fffad84c3f8 -[NSRegularExpression(NSMatching) enumerateMatchesInString:options:range:usingBlock:] + 375
    4   Foundation                          0x00007fffad899f66 -[NSRegularExpression(NSMatching) firstMatchInString:options:range:] + 156
    5   SwiftLintFramework                  0x000000010131374f _TFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A826attributeContainsParameterfT14attributeRangeVSC8_NSRange4lineV21SourceKittenFramework4Line4fileCS2_4File_Sb + 1551
    6   SwiftLintFramework                  0x0000000101312fb8 _TFFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A831createAlwaysOnNewLineAttributesFTGSaTSSSb__16attributesTokensGSaTSSVSC8_NSRange__4lineV21SourceKittenFramework4Line4fileCS2_4File_GVs3SetSS_U_FTSSS1__TSSSb_ + 776
    7   SwiftLintFramework                  0x0000000101318ecb _TPA__TFFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A831createAlwaysOnNewLineAttributesFTGSaTSSSb__16attributesTokensGSaTSSVSC8_NSRange__4lineV21SourceKittenFramework4Line4fileCS2_4File_GVs3SetSS_U_FTSSS1__TSSSb_ + 891
    8   SwiftLintFramework                  0x0000000101313a0b _TTRXFo_oSSdVSC8_NSRange_oSSdSbzoPs5Error__XFo_iTSSS___iTSSSb_zoPS0___ + 251
    9   SwiftLintFramework                  0x0000000101318fe4 _TPA__TTRXFo_oSSdVSC8_NSRange_oSSdSbzoPs5Error__XFo_iTSSS___iTSSSb_zoPS0___ + 148
    10  libswiftCore.dylib                  0x0000000101877ad6 _TFEsPs10Collection3mapurfzFzWx8Iterator7Element_qd__GSaqd___ + 838
    11  SwiftLintFramework                  0x00000001013128a2 _TFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A831createAlwaysOnNewLineAttributesfTGSaTSSSb__16attributesTokensGSaTSSVSC8_NSRange__4lineV21SourceKittenFramework4Line4fileCS2_4File_GVs3SetSS_ + 1458
    12  SwiftLintFramework                  0x000000010130de36 _TFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A811isViolationfT10lineNumberSi4fileC21SourceKittenFramework4File27attributeShouldBeOnSameLineSb_Sb + 3334
    13  SwiftLintFramework                  0x000000010130ae80 _TFV18SwiftLintFramework14AttributesRuleP33_DE7F7E58C782210DC97A8A1A7663B2A812validateKindfT4fileC21SourceKittenFramework4File27attributeShouldBeOnSameLineSb10dictionaryGVs10DictionarySSPS1_22SourceKitRepresentable___GSaVS_14StyleViolation_ + 1344
    14  SwiftLintFramework                  0x000000010130a880 _TFV18SwiftLintFramework14AttributesRule12validateFilefTC21SourceKittenFramework4File4kindOS1_20SwiftDeclarationKind10dictionaryGVs10DictionarySSPS1_22SourceKitRepresentable___GSaVS_14StyleViolation_ + 768
    15  SwiftLintFramework                  0x0000000101315b99 _TTWV18SwiftLintFramework14AttributesRuleS_7ASTRuleS_FS1_12validateFilefTC21SourceKittenFramework4File4kindwx8KindType10dictionaryGVs10DictionarySSPS2_22SourceKitRepresentable___GSaVS_14StyleViolation_ + 297
    16  SwiftLintFramework                  0x0000000101329092 _TFFe18SwiftLintFrameworkRxS_7ASTRuleWx8KindType8RawValue_zSSrS0_12validateFileFTC21SourceKittenFramework4File10dictionaryGVs10DictionarySSPS3_22SourceKitRepresentable___GSaVS_14StyleViolation_U_FGS5_SSPS6___GSaS7__ + 1698
    17  SwiftLintFramework                  0x00000001013293bf _TPA__TFFe18SwiftLintFrameworkRxS_7ASTRuleWx8KindType8RawValue_zSSrS0_12validateFileFTC21SourceKittenFramework4File10dictionaryGVs10DictionarySSPS3_22SourceKitRepresentable___GSaVS_14StyleViolation_U_FGS5_SSPS6___GSaS7__ + 191
    18  SwiftLintFramework                  0x0000000101329440 _TTRGRx18SwiftLintFramework7ASTRuleWx8KindType8RawValue_zSSrXFo_oGVs10DictionarySSP21SourceKittenFramework22SourceKitRepresentable___oGSaVS_14StyleViolation_zoPs5Error__XFo_iGS3_SSPS5____iGSaS6__zoPS7___ + 96
    19  SwiftLintFramework                  0x0000000101329682 _TPA__TTRGRx18SwiftLintFramework7ASTRuleWx8KindType8RawValue_zSSrXFo_oGVs10DictionarySSP21SourceKittenFramework22SourceKitRepresentable___oGSaVS_14StyleViolation_zoPs5Error__XFo_iGS3_SSPS5____iGSaS6__zoPS7___ + 242
    20  libswiftCore.dylib                  0x000000010194cb1f _TFEsPs8Sequence7flatMapuRd__S_rfzFzWx8Iterator7Element_qd__GSaWd__S0_S1___ + 639
    21  SwiftLintFramework                  0x0000000101328952 _TFe18SwiftLintFrameworkRxS_7ASTRuleWx8KindType8RawValue_zSSrS0_12validateFilefTC21SourceKittenFramework4File10dictionaryGVs10DictionarySSPS3_22SourceKitRepresentable___GSaVS_14StyleViolation_ + 626
    22  SwiftLintFramework                  0x000000010130a149 _TFV18SwiftLintFramework14AttributesRule12validateFilefC21SourceKittenFramework4FileGSaVS_14StyleViolation_ + 265
    23  SwiftLintFramework                  0x000000010131641d _TTWV18SwiftLintFramework14AttributesRuleS_4RuleS_FS1_12validateFilefC21SourceKittenFramework4FileGSaVS_14StyleViolation_ + 269
    24  SwiftLintFramework                  0x000000010113e9e3 _TFFV18SwiftLintFramework6LinterP33_5A5F37FCDEE0B4D78BAE05A90BA8A06218getStyleViolationsFSbTGSaVS_14StyleViolation_GSaT2idSS4timeSd___U_FPS_4Rule_GSaS1__ + 1203
    25  SwiftLintFramework                  0x00000001011438b6 _TPA__TFFV18SwiftLintFramework6LinterP33_5A5F37FCDEE0B4D78BAE05A90BA8A06218getStyleViolationsFSbTGSaVS_14StyleViolation_GSaT2idSS4timeSd___U_FPS_4Rule_GSaS1__ + 310
    26  SwiftLintFramework                  0x000000010135a651 _TTRG__rXFo_ix_oGSaqd____XFo_ix_iGSaqd____ + 81
    27  SwiftLintFramework                  0x000000010135a802 _TPA__TTRG__rXFo_ix_oGSaqd____XFo_ix_iGSaqd____ + 226
    28  SwiftLintFramework                  0x000000010135afab _TFFE18SwiftLintFrameworkSa11parallelMapurFT9transformFxqd___GSaqd___U_FSiT_ + 555
    29  SwiftLintFramework                  0x000000010135b3b0 _TPA__TFFE18SwiftLintFrameworkSa11parallelMapurFT9transformFxqd___GSaqd___U_FSiT_ + 336
    30  libclang_rt.tsan_osx_dynamic.dylib  0x00000001001679e2 __wrap_dispatch_apply_block_invoke + 98
    31  libdispatch.dylib                   0x00000001020e896f _dispatch_client_callout2 + 8
    32  libdispatch.dylib                   0x00000001020ed107 _dispatch_apply_serial + 108
    33  libdispatch.dylib                   0x00000001020daf5c _dispatch_client_callout + 8
    34  libdispatch.dylib                   0x00000001020f22fa _dispatch_sync_function_invoke + 288
    35  libdispatch.dylib                   0x00000001020e82a7 dispatch_apply_f + 459
    36  libclang_rt.tsan_osx_dynamic.dylib  0x0000000100167955 wrap_dispatch_apply + 261
    37  libswiftCore.dylib                  0x0000000101aa4058 _swift_dispatch_apply_current + 72
    38  libswiftDispatch.dylib              0x0000000101daf3f4 _TZFE8DispatchCSo13DispatchQueue17concurrentPerformfT10iterationsSi7executeFSiT__T_ + 116
    39  SwiftLintFramework                  0x000000010135a1fb _TFE18SwiftLintFrameworkSa11parallelMapurfT9transformFxqd___GSaqd___ + 1979
    40  SwiftLintFramework                  0x000000010135980e _TFE18SwiftLintFrameworkSa15parallelFlatMapurfT9transformFxGSaqd____GSaqd___ + 318
    41  SwiftLintFramework                  0x000000010113e440 _TFV18SwiftLintFramework6LinterP33_5A5F37FCDEE0B4D78BAE05A90BA8A06218getStyleViolationsfSbTGSaVS_14StyleViolation_GSaT2idSS4timeSd___ + 848
    42  SwiftLintFramework                  0x000000010113e0d1 _TFV18SwiftLintFramework6Linterg15styleViolationsGSaVS_14StyleViolation_ + 65
    43  swiftlint                           0x0000000100019c60 _TFFV9swiftlint11LintCommand3runFVS_11LintOptionsGO6Result6ResultT_GO10Commandant15CommandantErrorT___U_FV18SwiftLintFramework6LinterT_ + 1616
    44  swiftlint                           0x000000010001a3cf _TPA__TFFV9swiftlint11LintCommand3runFVS_11LintOptionsGO6Result6ResultT_GO10Commandant15CommandantErrorT___U_FV18SwiftLintFramework6LinterT_ + 1055
    45  swiftlint                           0x000000010000b631 _TFFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U_FS6_T_U0_FT_T_ + 1537
    46  swiftlint                           0x000000010000e013 _TPA__TFFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U_FS6_T_U0_FT_T_ + 1171
    47  swiftlint                           0x000000010000b702 _TTRXFo__zoPs5Error__XFo__iT_zoPS___ + 50
    48  swiftlint                           0x000000010000e11c _TPA__TTRXFo__zoPs5Error__XFo__iT_zoPS___ + 140
    49  libswiftObjectiveC.dylib            0x0000000101fe34d6 _TF10ObjectiveC15autoreleasepoolurFzT8invokingFzT_x_x + 54
    50  swiftlint                           0x000000010000a683 _TFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U_FS6_T_ + 3235
    51  swiftlint                           0x000000010000d6cf _TPA__TFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U_FS6_T_ + 1583
    52  swiftlint                           0x000000010000b7fb _TFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U0_FSiT_ + 123
    53  swiftlint                           0x000000010000d97a _TPA__TFFFE9swiftlintV18SwiftLintFramework13Configuration18visitLintableFilesFTSS6actionSS8useSTDINSb5quietSb19useScriptInputFilesSb8parallelSb12visitorBlockFVS0_6LinterT__GO6Result6ResultGSaC21SourceKittenFramework4File_GO10Commandant15CommandantErrorT___U0_FGSaS6__GS4_GSaS6__GS8_T___U0_FSiT_ + 170
    54  libclang_rt.tsan_osx_dynamic.dylib  0x00000001001679e2 __wrap_dispatch_apply_block_invoke + 98
    55  libdispatch.dylib                   0x00000001020e896f _dispatch_client_callout2 + 8
    56  libdispatch.dylib                   0x00000001020e87b4 _dispatch_apply_invoke + 147
    57  libdispatch.dylib                   0x00000001020daf5c _dispatch_client_callout + 8
    58  libdispatch.dylib                   0x00000001020dd48c _dispatch_root_queue_drain + 1364
    59  libdispatch.dylib                   0x00000001020dcee8 _dispatch_worker_thread3 + 114
    60  libsystem_pthread.dylib             0x000000010215289a _pthread_wqthread + 1299
    61  libsystem_pthread.dylib             0x0000000102152375 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Jan 1, 2017
@jpsim
Copy link
Collaborator Author

jpsim commented Jan 1, 2017

Reduced crasher to @objc class ⽺ {}.

@jpsim
Copy link
Collaborator Author

jpsim commented Jan 1, 2017

I have to leave, but here's the fix:

diff --git a/Source/SwiftLintFramework/Rules/AttributesRule.swift b/Source/SwiftLintFramework/Rules/AttributesRule.swift
index 598936b..57b1f74 100644
--- a/Source/SwiftLintFramework/Rules/AttributesRule.swift
+++ b/Source/SwiftLintFramework/Rules/AttributesRule.swift
@@ -258,15 +258,14 @@ public struct AttributesRule: ASTRule, OptInRule, ConfigurationProviderRule {
         let restOfLineOffset = attributeRange.location + attributeRange.length
         let restOfLineLength = line.byteRange.location + line.byteRange.length - restOfLineOffset
 
-        let range = NSRange(location: 0, length: restOfLineLength)
         let regex = AttributesRule.regularExpression
         let contents = file.contents.bridge()
 
         // check if after the token is a `(` with only spaces allowed between the token and `(`
         guard let restOfLine = contents.substringWithByteRange(start: restOfLineOffset,
                                                                length: restOfLineLength),
+            case let range = NSRange(location: 0, length: restOfLine.bridge().length),
             regex.firstMatch(in: restOfLine, options: [], range: range) != nil else {
-
             return false
         }
 
diff --git a/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift b/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
index 9fcb07b..2fba66a 100644
--- a/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
+++ b/Source/SwiftLintFramework/Rules/AttributesRulesExamples.swift
@@ -35,6 +35,7 @@ internal struct AttributesRuleExamples {
         "@objc(ABCThing)\n @available(iOS 9.0, *)\n class Thing",
         "class Foo: NSObject {\n override var description: String { return \"\" }\n}",
         "class Foo: NSObject {\n\n override func setUp() {}\n}",
+        "@objc\nclass ⽺ {}\n",
 
         // attribute with allowed empty new line above
         "extension Property {\n\n @available(*, unavailable, renamed: \"isOptional\")\n" +

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

1 participant