stencilproject/Stencil

Crashes in `Lexer.createToken`

jberkel opened this issue · 1 comments

On {%} and {{}}.

See https://github.com/jberkel/Stencil/commit/40a106282a999c1dda0829986426e14be8c589a6 for testcases

fatal error: Can't form Range with upperBound < lowerBound
Current stack trace:
0    libswiftCore.dylib                 0x000000010f8b7130 swift_reportError + 129
1    libswiftCore.dylib                 0x000000010f8d3b50 _swift_stdlib_reportFatalError + 60
2    libswiftCore.dylib                 0x000000010f6c4250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
3    libswiftCore.dylib                 0x000000010f83ee90 partial apply for (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x000000010f6c4250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5    libswiftCore.dylib                 0x000000010f7f19a0 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96
6    StencilPackageTests                0x000000010f572c20 Lexer.(createToken(string : String) -> Token).(strip #1)() -> String + 376
7    StencilPackageTests                0x000000010f5729f0 Lexer.createToken(string : String) -> Token + 265
8    StencilPackageTests                0x000000010f573320 Lexer.tokenize() -> [Token] + 2019
9    StencilPackageTests                0x000000010f508eb0 (testLexer() -> ()).(closure #1).(closure #7) + 76
fatal error: cannot decrement before startIndex
Current stack trace:
0    libswiftCore.dylib                 0x00000001058b7130 swift_reportError + 129
1    libswiftCore.dylib                 0x00000001058d3b50 _swift_stdlib_reportFatalError + 60
2    libswiftCore.dylib                 0x00000001056c4250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
3    libswiftCore.dylib                 0x000000010583ee90 partial apply for (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #2) + 109
4    libswiftCore.dylib                 0x00000001056c4250 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5    libswiftCore.dylib                 0x00000001057f19a0 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96
6    libswiftCore.dylib                 0x00000001057b3fa0 String.index(before : String.CharacterView.Index) -> String.CharacterView.Index + 294
7    StencilPackageTests                0x0000000105574e50 String.findLastNot(character : Character) -> String.CharacterView.Index? + 121
8    StencilPackageTests                0x0000000105572ea0 String.trim(character : Character) -> String + 504
9    StencilPackageTests                0x0000000105572c40 Lexer.(createToken(string : String) -> Token).(strip #1)() -> String + 533
10   StencilPackageTests                0x0000000105572a10 Lexer.createToken(string : String) -> Token + 156
kylef commented

Thanks for the report, I really appreciate that you provided a test case in your bug report. I've extended on your tests and made a fix in 482d595.