Skip to content

Commit

Permalink
Fixed RD-15094: Json.Reader going in an infinite loop upon parse erro…
Browse files Browse the repository at this point in the history
…rs (#533)
  • Loading branch information
bgaidioz authored Nov 14, 2024
1 parent ca7e531 commit ea943aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ public abstract static class ParseStringJsonParserNode extends Node {
@TruffleBoundary
static String doParse(Node node, JsonParser parser, @Bind("$node") Node thisNode) {
try {
if (!parser.currentToken().isScalarValue()) {
throw new JsonParserTruffleException(
"unexpected token: " + parser.currentToken(), thisNode);
JsonToken token = parser.currentToken();
if (!token.isScalarValue()) {
throw new JsonParserTruffleException("unexpected token: " + token, thisNode);
}
String v = parser.getText();
parser.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ private Integer getFieldNameIndex(String fieldName) {

@CompilerDirectives.TruffleBoundary
private void executeWhileLoop(JsonParser parser, BitSet currentBitSet, Object record) {
while (currentTokenNode.execute(this, parser) != JsonToken.END_OBJECT) {
while (currentTokenNode.execute(this, parser) != JsonToken.END_OBJECT
&& currentTokenNode.execute(this, parser) != null) {
String fieldName = currentFieldNode.execute(this, parser);
Integer index = this.getFieldNameIndex(fieldName);
nextTokenNode.execute(this, parser); // skip the field name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public OSRListParseJsonConditionNode(int parserSlot) {
@Override
public Object executeGeneric(VirtualFrame frame) {
JsonParser parser = (JsonParser) frame.getObject(parserSlot);
return currentToken.execute(this, parser) != JsonToken.END_ARRAY;
JsonToken token = currentToken.execute(this, parser);
return token != JsonToken.END_ARRAY && token != null;
}

@Override
Expand Down

0 comments on commit ea943aa

Please sign in to comment.