From fa2d9061970645554be3287909e6caf303be0449 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Thu, 3 Aug 2023 12:03:29 +0000 Subject: [PATCH 1/2] Fix invalid character handling Signed-off-by: Arthur Chan --- src/org/joni/Lexer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/org/joni/Lexer.java b/src/org/joni/Lexer.java index 3ac3338..596c26b 100644 --- a/src/org/joni/Lexer.java +++ b/src/org/joni/Lexer.java @@ -1174,7 +1174,12 @@ protected final void fetchToken() { token.type = TokenType.CODE_POINT; token.setCode(c); } else { /* string */ - p = token.backP + enc.length(bytes, token.backP, stop); + int encLength = enc.length(bytes, token.backP, stop); + /* Check and ensure the encoded character is valid */ + if (encLength == Encoding.CHAR_INVALID) { + throw new IllegalArgumentException("Invalid character found."); + } + p = token.backP + encLength; } break; } // switch (c) From c13a66a08ee4910a56535e24dbcde553922752fb Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 4 Aug 2023 18:07:05 +0000 Subject: [PATCH 2/2] Fix missing import statement Signed-off-by: Arthur Chan --- src/org/joni/Lexer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/joni/Lexer.java b/src/org/joni/Lexer.java index 596c26b..daa3c8e 100644 --- a/src/org/joni/Lexer.java +++ b/src/org/joni/Lexer.java @@ -24,6 +24,7 @@ import static org.joni.Option.isWordBoundAllRange; import static org.joni.ast.QuantifierNode.isRepeatInfinite; +import org.jcodings.Encoding; import org.jcodings.Ptr; import org.jcodings.constants.CharacterType; import org.jcodings.exception.CharacterPropertyException;