rubys / nokogumbo

A Nokogiri interface to the Gumbo HTML5 parser.
Apache License 2.0
186 stars 114 forks source link

Fix reading passed the end of the source buffer #128

Closed stevecheckoway closed 5 years ago

stevecheckoway commented 5 years ago

When constructing an error message for an unexpected EOF, the error text pointer is one byte passed the end of our source text. It's invalid to read from that pointer. Instead, be explicit about our source buffer by giving a size and assert that the error is either within the buffer or one byte after.

Make a similar change for finding the next new line and fix the comment. There's not always a trailing zero byte, but the result is the same. It either returns a pointer to the next new line, or it returns a pointer one passed the end of the source buffer.

stevecheckoway commented 5 years ago

This was found with address sanitizer and AFL.