Skip to content
Myr

Only care about RS when parsing with --seq

Before adoption: this commit came in with the history the project adopted, so no landing records it.

RS should only only have special meaning when parsing json-seq. Before this fix, RS was sometimes treated as a value terminator, causing weird results. Bug discovered by OSS fuzz. Ref: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60835

authored by Emanuele Torre · committed by Nico Williams · parent ae95864 · Browse files · 1 file+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−5 removed

  • other:+6 added−5 removed

1 file+6 added−5 removed

modified:src/jv_parse.c+6 added-5 removed
608 unmodified lines
609 return 0;610 }611}612613static int parse_check_truncation(struct jv_parser* p) {614 return ((p->flags & JV_PARSE_SEQ) && !p->last_ch_was_ws && (p->stackpos > 0 || p->tokenpos > 0 || jv_get_kind(p->next) == JV_KIND_NUMBER));613static int seq_check_truncation(struct jv_parser* p) {614 return (!p->last_ch_was_ws && (p->stackpos > 0 || p->tokenpos > 0 || jv_get_kind(p->next) == JV_KIND_NUMBER));615}616617static int stream_check_truncation(struct jv_parser* p) {617static int stream_seq_check_truncation(struct jv_parser* p) {618 jv_kind k = jv_get_kind(p->next);619 return (p->stacklen > 0 || k == JV_KIND_NUMBER || k == JV_KIND_TRUE || k == JV_KIND_FALSE || k == JV_KIND_NULL);620}621
11 unmodified lines
633#define token(p, ch) \634 (((p)->flags & JV_PARSE_STREAMING) ? stream_token((p), (ch)) : parse_token((p), (ch)))635636#define check_truncation(p) \637 (((p)->flags & JV_PARSE_STREAMING) ? stream_check_truncation((p)) : parse_check_truncation((p)))637 (((p)->flags & JV_PARSE_STREAMING) ? stream_seq_check_truncation((p)) : seq_check_truncation((p)))638639#define is_top_num(p) \640 (((p)->flags & JV_PARSE_STREAMING) ? stream_is_top_num((p)) : parse_is_top_num((p)))641
2 unmodified lines
644 if (ch == '\n') {645 p->line++;646 p->column = 0;647 }648 if ((p->flags & JV_PARSE_SEQ)648 if (ch == '\036' /* ASCII RS; see draft-ietf-json-sequence-07 */) {649 && ch == '\036' /* ASCII RS; see draft-ietf-json-sequence-07 */) {650 if (check_truncation(p)) {651 if (check_literal(p) == 0 && is_top_num(p))652 return "Potentially truncated top-level numeric value";653 return "Truncated value";
250 unmodified lines