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

Gson can throw StackOverFlowError which will most likely not be caught #2161

Closed
fan87 opened this issue Jul 28, 2022 · 3 comments
Closed

Gson can throw StackOverFlowError which will most likely not be caught #2161

fan87 opened this issue Jul 28, 2022 · 3 comments
Labels

Comments

@fan87
Copy link

fan87 commented Jul 28, 2022

Gson version

2.9.0

Description

Gson could throw StackOverFlowError with "[" * 8000, but most people will only catch Exception, not Error.

I don't think it's a real "security" vuln since most servers would catch every Throwable thrown by the code that handles the request instead of just killing the entire server but just in case.

Expected behavior

Throws a JSON syntax exception

Actual behavior

Throws an Error, which most people won't be catching

Reproduction steps

        Gson gson = new Gson();
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < 8000; i++) {
            out.append("[");
        }

        try {
            gson.fromJson(out.toString(), JsonArray.class);
        } catch (Exception ignored) {
            System.out.println("Invalid Json Body!");
            // Most people will only be catching Exception, not Error
        }

Exception stack trace

(What a normal StackOverFlowError stacktrace looks like)

        (repeated until it throws stackoverflowerror)
	at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:718)
@fan87 fan87 added the bug label Jul 28, 2022
@eamonnmcmanus
Copy link
Member

I think this is probably fixed by #1912. However we haven't made a release with that change in it yet. If you're motivated, you could try building a current snapshot and seeing if the problem persists there.

@Marcono1234
Copy link
Collaborator

@fan87, with Gson 2.9.1 having been released, could you please check if this issue still occurs?

@fan87
Copy link
Author

fan87 commented Aug 3, 2022

Yes it's fixed

@fan87 fan87 closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants