From 4c5a1dad0a7e9fb70a830d9312352b855abfc7cb Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 28 Aug 2024 09:33:01 -0400 Subject: [PATCH] [PRISM] Check length of line for shebang --- prism/prism.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prism/prism.c b/prism/prism.c index 9ab45f1cc3..ff5d5c2ccc 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -21961,10 +21961,10 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm // If the first two bytes of the source are a shebang, then we'll indicate // that the encoding comment is at the end of the shebang. - if (peek(parser) == '#' && peek_offset(parser, 1) == '!') { - const uint8_t *newline = next_newline(parser->start, parser->end - parser->start); - size_t length = (size_t) ((newline != NULL ? newline : parser->end) - parser->start); + const uint8_t *newline = next_newline(parser->start, parser->end - parser->start); + size_t length = (size_t) ((newline != NULL ? newline : parser->end) - parser->start); + if (length > 2 && parser->current.end[0] == '#' && parser->current.end[1] == '!') { const char *engine; if ((engine = pm_strnstr((const char *) parser->start, "ruby", length)) != NULL) { if (newline != NULL) {