cups icon indicating copy to clipboard operation
cups copied to clipboard

JSON import accepts missing separators and values

Open Shubham-Padkonde opened this issue 1 month ago • 1 comments

cupsJSONImportString() accepts malformed object/array separators, missing values, and extra text after the root object.

Reproduced on master 2fde0aa06044a596c77919a166b020819d7168ae with cups/testjson:

cupsJSONImportString("{\"a\":1 \"b\":2}"); // Missing comma.
cupsJSONImportString("{\"a\":[1 2]}");     // Missing comma in array.
cupsJSONImportString("{\"a\":1,}");       // Trailing comma.
cupsJSONImportString("{\"a\":}");         // Missing value.
cupsJSONImportString("{} trailing text");

Each returns a JSON object instead of reporting invalid data. In particular, accepting a missing value produces an object with an unmatched key. Nested objects/arrays show the same separator behavior.

The separator logic currently validates a comma/colon if one is present but does not consistently require it, and parsing stops at the first completed root object without checking the remaining input. RFC 8259 defines the object and array separators and requires a value after each key's colon.

A regression table covering 21 valid/invalid examples produces 11 failures before the fix. Requiring separators and values and checking the text after the root makes all 21 pass, including empty containers, nested containers, and surrounding whitespace.

The existing external Google HTTPS test separately fails certificate validation in this local environment; that failure is unchanged.

Shubham-Padkonde avatar Oct 26 '26 13:10 Shubham-Padkonde

Again, please don't file duplicate issues/PRs.

michaelrsweet avatar Oct 26 '26 14:10 michaelrsweet