buffer_skip_whitespace accepts every byte below 0x21 as whitespace

Open Beginner friendly
#1,074 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c

Research direction

Start at the buffer_skip_whitespace loop reached through cJSON_ParseWithLengthOpts and inspect how bytes below 0x21 are classified. Restrict whitespace handling to space, tab, LF, and CR, then verify that the shown control-byte inputs are rejected while valid JSON whitespace remains accepted.

Written by the indexing model from the issue text.

Description

buffer_skip_whitespace skips any byte <= 32, so NUL, 0x01, 0x0b, 0x1f, and every other control byte are accepted as whitespace between tokens. JSON whitespace is only space, tab, LF, and CR. With cJSON_ParseWithLengthOpts the NUL case is reachable too:

cJSON_ParseWithLengthOpts("[\x0b1]", 5, NULL, 1);   /* [1] */
cJSON_ParseWithLengthOpts("[\x011]", 5, NULL, 1);   /* [1] */
cJSON_ParseWithLengthOpts("\x00null", 6, NULL, 1);  /* null */

Form feed is in the JSONTestSuite list in #877 and control characters inside strings are #871; the other bytes between tokens are not in either. Found on v1.7.19 with a property that splices one control byte at a random offset of a valid document. A fix is to accept only ' ', '\t', '\n', '\r' in that loop.

Dominant language
C
Stars
13k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DaveGamble/cJSON

All issues in DaveGamble/cJSON

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.