Skip to content

Commit

Permalink
Tokenizer: prevent OOB read when processing #embed directive
Browse files Browse the repository at this point in the history
If a colon appeared at the end of an embed directive and was the
last byte in a file, we would do an out of bounds read trying to
tokenize a double colon.
  • Loading branch information
ehaas committed Mar 30, 2024
1 parent 30c93ed commit 4f4e2d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aro/Tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ pub fn nextNoWSComments(self: *Tokenizer) Token {
/// Try to tokenize a '::' even if not supported by the current language standard.
pub fn colonColon(self: *Tokenizer) Token {
var tok = self.nextNoWS();
if (tok.id == .colon and self.buf[self.index] == ':') {
if (tok.id == .colon and self.index < self.buf.len and self.buf[self.index] == ':') {
self.index += 1;
tok.id = .colon_colon;
}
Expand Down
3 changes: 3 additions & 0 deletions test/cases/colon after #embed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define NO_ERROR_VALIDATION

#embed "embed byte"n:

0 comments on commit 4f4e2d5

Please sign in to comment.