h0tk3y/better-parse

A StringIndexOutOfBoundsException occurs in this library

Opened this issue · 0 comments

Hello, I have observed some issues with this library as follows.
Class com.github.h0tk3y.betterParse.lexer.TokenMatch.getText() does not perform a boundary checking of the parameters in the method subSequence(this.offset, this.offset + this.length).toString(), which cause ‘java.lang.StringIndexOutOfBoundsException’.

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 5, end 28, length 8
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4608)
at java.base/java.lang.String.substring(String.java:2711)
at java.base/java.lang.String.subSequence(String.java:2749)
at com.github.h0tk3y.betterParse.lexer.TokenMatch.getText(TokenMatch.kt:18)
at com.github.h0tk3y.betterParse.lexer.TokenMatch.toString(TokenMatch.kt:24)
at java.base/java.lang.String.valueOf(String.java:4222)
at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
at com.github.h0tk3y.betterParse.parser.UnparsedRemainder.toString(Parser.kt)

It suggests that the library can conduct a boundary checking of the parameter in the method subSequence to ensure this method can accept the suitable parameters and avoid the running code to stop throwing a StringIndexOutOfBoundsException.