MDEV-41898 JSON_VALID accepts a number with an empty exponent ('1e') inside arrays and objects #6248
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #6248"
general
weight: 0.35
gkodinov
Problem
A number whose exponent has no digits (
1e,1e+,1E-), or a lone-, isnot valid JSON. It is rejected at the top level, but accepted as soon as it sits
inside an array or object:
| Input | Before | After |
|---|---|---|
|
1e|0|0||
[1e],{"a":1e},[1e,2],[1e ]|1|0||
[1e+],[1E-],[0e],[1.5e]|1|0||
[-],{"a":-}|1|0||
1e+-5,[1e--+5],1e++5,{"a":1E-+5}(repeated exponent sign) |1|0||
JSON_VALUE('[1e]', '$[0]')|1e|NULL||
[1e5],{"a":1E+5},[1e-5, 2],[-1 ]|1|1(unchanged) |Root cause
skip_num_constant()(strings/json_lib.c) scans a number one character at atime through the
json_num_statestable. There are two ways the number can stop:json_num_states[state][N_END], i.e. whetherthe number can end in its current state, and fails if not. That is why
'1e'is rejected.
],,,}and whitespace are classN_END, so the lookup is the same "can the number end here?" check, and foran incomplete number it returns
JE_SYN. But the loopbreaks on anynon-positive result without telling
NS_OKfrom an error, so the error islost and the scanner carries on as if a complete number had been read.
Repeated exponent signs
A second, independent defect sits in the same table. JSON allows at most one
sign after the exponent marker, but the
EXrow sends-and+back toNS_EXitself, so any number of signs is consumed before the digits:This is accepted everywhere, top level included:
JSON_VALID('1e+-5')andJSON_VALID('[1e--+5]')both return1.Fix
When the number stops at a character that is not part of it, apply the same
N_ENDcheck as at the end of the text and fail with its error:The check is on the state the number was in (its
N_ENDtransition), not onthe failed transition. So:
[1x]) is stillreported by the code that reads the next token, as before — its error code and
position do not change;
JE_SYNthe top-level casealready reported, at the position of the delimiter.
Add a state for the exponent sign,
NS_EXS.EXmoves to it on-or+, andNS_EXSaccepts only a digit, so a second sign isJE_SYN. It cannot end thenumber either, so
1e+is still rejected via theN_ENDcheck above:The new state carries no
num_flags(JSON_NUM_EXPis already set byNS_EX),and the states are private to
json_lib.c, so nothing else is affected.Testing
Added to
mysql-test/main/func_json.test. Verified failing before the change(10 of the 11 incomplete numbers returned
1,JSON_VALUE('[1e]','$[0]')returned
1e, and the four repeated-sign cases returned1) and passing after. It covers:],,,}and whitespace;1e+,1E-), and after0and a fraction;-in an array and in an object;1e+-5,[1e--+5],1e++5,{"a":1E-+5},[1e+-]), at the top level and nested, with a single sign (1e+5,1E-5)still valid;
JSON_VALUEno longer returning the incomplete number, andJSON_EXTRACTreporting the error at the delimiter rather than inside its own result;
pass by over-rejecting.
The parser is shared by every JSON function, by JSON histograms and by
mysql.global_priv, so the suites covering those callers were run in full:| Suite | Result |
|---|---|
| all JSON tests (
jsonsuite,main.json) | 38/38 pass ||
main,roles,json(full) | 1293/1293 pass ||
main.func_json, embedded server | pass |No existing result file changed, so no existing error message or position moved.
---
All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
Assisted-by: Claude:claude-opus-5-5