vapor / template-kit

📄 Easy-to-use foundation for building powerful templating languages in Swift.
MIT License
46 stars 17 forks source link

Index out of range in peek of TemplateByteScanner #49

Closed edmw closed 5 years ago

edmw commented 5 years ago

Affected version: 1.1.2

With some of my leaf templates the method peek of TemplateByteScanner will be called with a negative amount. When the current pointer is less than the absolute amount this will cause a Fatal Error: Index out of range.

Adding a guard pointer + amount >= 0 else return nil fixed this for me.

The good thing is, the former version using an unsafe pointer most likely resulted in a buffer overflow.

foscomputerservices commented 5 years ago

I added pull request #48 to fix this very thing yesterday. I too encountered this when leaf was scanning the beginning of of file for #//.

let isEntirelyCommentLine: Bool = (peek(by: -4) == .newLine)
tanner0101 commented 5 years ago

Fixed by #48, thanks!