Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing JSON with ALLOW_MISSING_VALUE enabled results in endless stream of VALUE_NULL tokens #616

Closed
jusliu opened this issue May 10, 2020 · 5 comments
Milestone

Comments

@jusliu
Copy link

jusliu commented May 10, 2020

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;

public class Test {
	public static void main(String[] args) {
		String content = ",";
		JsonFactory f = new JsonFactory().configure(Feature.ALLOW_MISSING_VALUES, true);
		try {
			JsonParser parser = f.createJsonParser(content);
			JsonToken current = parser.nextToken();

			// this will result in an infinite loop
			while (parser.hasCurrentToken()) {
				System.out.println(current); // prints VALUE_NULL
				current = parser.nextToken();
			}
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

This code results in an infinite loop. Only happens with ALLOW_MISSING_VALUES enabled. Treats the unexpected comma as a missing value or something, replacing it with NULL, but on the top-level this results in an infinite loop where nextToken() will return VALUE_NULL forever.

Also happens on inputs including:

  1. [],
  2. {"foo": "bar"},
@cowtowncoder
Copy link
Member

Thank you for reporting this. Which version is this verified with?

@jusliu
Copy link
Author

jusliu commented May 11, 2020

I was originally using 2.10.1, but I just tested this on 2.11.0 and it's still occurring.

@cowtowncoder
Copy link
Member

Added failing test.

@cowtowncoder
Copy link
Member

One quick note: commas should not really be accepted as separators in root level so just realizing that this needs to result in parsing error. But bit worried that someone somewhere might already be relying on such behavior...

@cowtowncoder cowtowncoder changed the title Parsing JSON with ALLOW_MISSING_VALUE enabled results in infinite loop on top-level commas Parsing JSON with ALLOW_MISSING_VALUE enabled results in endless stream of VALUE_NULL tokens May 12, 2020
cowtowncoder added a commit that referenced this issue May 12, 2020
@cowtowncoder cowtowncoder added this to the 2.10.5 milestone May 12, 2020
@cowtowncoder
Copy link
Member

Fixed: will now report parsing error for root-level commas, which will also prevent infinite sequences of VALUE_NULLs. Fix will be in 2.10.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants