From 5754074c1519cb6ef375fd54f0afe30090bcf508 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 21:04:14 -0700 Subject: [PATCH] Fix read out of bounds with empty file (#665) --- src/lparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index 82ac34a1..f0eea74b 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -2326,8 +2326,8 @@ int luaY_parser(terra_State *T, ZIO *z, const char *name, int firstchar) { lexstate.output_buffer.data); } // loadbuffer doesn't like null terminators, so rewind to before them - while (lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0' && - lexstate.output_buffer.N > 0) { + while (lexstate.output_buffer.N > 0 && + lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0') { lexstate.output_buffer.N--; }