GNOME Bugzilla – Bug 725397
assertion failure from malformed input
Last modified: 2017-09-05 10:40:23 UTC
json-glib fails with an assertion failure with some types of malformed JSON inputs. See bug #723368 comment #17 for an example of this: https://bugzilla.gnome.org/show_bug.cgi?id=723368#c17 This is unfortunate because the JSON input comes from a REST response and is not under our control. A GError response would be much better: applications shouldn't crash when a server gives an expected response. This particular case came about because the Google Cloud Print service responds to a POST /submit request with a JSON object containing the entire response, including "content" (the contents of a PDF file) as a string.
JsonParser should never crash; malformed JSON should just give a JSON_PARSER_ERROR. in the bug you linked you're tripping an assertion in the underlying tokenizer. it seems the source is violating the JSON spec as well. to be fair, you should ask the server to fix their JSON: it's utterly broken, and you cannot know how any other JSON parser will behave when it comes to broken Unicode surrogate pairs. brokenness of input begets undefined behaviour. in any case, I can probably replace the assert() with a scanner error, which would be raised up to the JsonParser.
it turns out that some stuff in JsonScanner (our internal fork of GScanner) simply cannot be reported as errors: we have assertions all over the place, and even if we just ignored malformed data we would not be able to get a GError in place for caller code to handle. this will have to wait once we have a new tokenizer in place. I'm marking this bug as being blocked by bug 725507.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/json-glib/issues/10.