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

JsonToken::asObject() odd behavior with empty objects #174

Closed
pezcode opened this issue Aug 2, 2023 · 2 comments
Closed

JsonToken::asObject() odd behavior with empty objects #174

pezcode opened this issue Aug 2, 2023 · 2 comments

Comments

@pezcode
Copy link
Contributor

pezcode commented Aug 2, 2023

JsonToken::asObject() behaves in interesting ways given the following json:

{
}

In our code, we're getting access violation exceptions due to bogus pointer values, and the attached patch to UtilityJsonTest produces an odd error message:

Utility::JsonToken::find(): token is a parsed Utility::JsonToken::Type::Number, expected a parsed object

corrade-14-15-21.patch

@mosra mosra added this to the 2023.0a milestone Aug 2, 2023
@mosra
Copy link
Owner

mosra commented Aug 2, 2023

Argh, that was a silly unhandled corner case, especially with the comment next to it saying that "it should never happen". Sorry about that. Most of the uses of find() or operator[]() happen directly on a JsonToken, performing that on a JsonObjectView / JsonArrayView is a rather rare scenario which probably explains I never encountered this case so far.

Fixed in fa7fa30, and although I managed to find a case where this would produce a similar assertion (and another case where it'd just silently produce a wrong result), your patch triggered a plain segfault on a null pointer in my case, not the error you reported.

@mosra mosra closed this as completed Aug 2, 2023
@pezcode
Copy link
Contributor Author

pezcode commented Aug 2, 2023

Thank you for the quick fix ☺️ Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants