Skip to content
Myr

Reject NaN with payload while parsing JSON

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

This commit drops support for parsing NaN with payload in JSON like `NaN123` and fixes CVE-2024-53427. Other JSON extensions like `NaN` and `Infinity` are still supported. Fixes #3023, fixes #3196, fixes #3246.

authored by itchyny · committed by itchyny · parent a8ce2ff · Browse files · 3 files+15 added−11 removed
This commit

State

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

Diff stats

3 files+15 added−11 removed

  • tests:+10 added−11 removed
  • other:+5 added−0 removed

3 files+15 added−11 removed

modified:src/jv.c+5 added
583 unmodified lines
584 jv_mem_free(n);585 return JV_INVALID;586 }587 if (decNumberIsNaN(&n->num_decimal)) {588 // Reject NaN with payload.589 if (n->num_decimal.digits > 1 || *n->num_decimal.lsu != 0) {590 jv_mem_free(n);591 return JV_INVALID;592 }593 jv_mem_free(n);594 return jv_number(NAN);595 }596
1446 unmodified lines
modified:tests/jq.test+10 added-4 removed
2108 unmodified lines
2109tojson | fromjson2110{"a":nan}2111{"a":null}21122113# also "nan with payload" #29852114if have_decnum then fromjson else nan end | isnan2115"nan1234"2113# NaN with payload is not parsed2114.[] | try (fromjson | isnan) catch .2115["NaN","-NaN","NaN1","NaN10","NaN100","NaN1000","NaN10000","NaN100000"]2116true2117true2118"Invalid numeric literal at EOF at line 1, column 4 (while parsing 'NaN1')"2119"Invalid numeric literal at EOF at line 1, column 5 (while parsing 'NaN10')"2120"Invalid numeric literal at EOF at line 1, column 6 (while parsing 'NaN100')"2121"Invalid numeric literal at EOF at line 1, column 7 (while parsing 'NaN1000')"2122"Invalid numeric literal at EOF at line 1, column 8 (while parsing 'NaN10000')"2123"Invalid numeric literal at EOF at line 1, column 9 (while parsing 'NaN100000')"212421182125# calling input/0, or debug/0 in a test doesn't crash jq21262127try input catch .2128null
193 unmodified lines
modified:tests/shtest-7 removed
667 unmodified lines
668 echo 'multiline comment with CRLF line breaks was not handled correctly'669 exit 1670fi671672# CVE-2023-50268: No stack overflow comparing a nan with a large payload673if $JQ -ne 'have_decnum'; then674 $VALGRIND $Q $JQ '1 != .' <<\EOF >/dev/null675 Nan4000676EOF677fi678672# Allow passing the inline jq script before -- #2919673if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then674 echo "passing the inline script after -- didn't work"675 exit 1
71 unmodified lines