Repository navigation
Field::restoreFromDump: read the UUID/IPv4/IPv6 dumps Field::dump writes; prefix-check other dumps - #121052
Field::restoreFromDump: read the UUID/IPv4/IPv6 dumps Field::dump writes; prefix-check other dumps#121052qoega wants to merge 5 commits into
Conversation
…::dump writes `FieldVisitorDump` writes `UUID_'...'`, `IPv4_'...'` and `IPv6_'...'`, but `Field::restoreFromDump` had no branch for them, so a `Literal` of these types could not be deserialized from the JSON AST (`CANNOT_RESTORE_FROM_FIELD_DUMP`). `JSONObjectReader::readFieldFromObjectImpl` now requires the dump payload to start with `<field_type>_`; before, a payload such as `'VALUE&` declared as `UUID` was handed to the `String` reader and leaked `CANNOT_PARSE_QUOTED_STRING` instead of `BAD_ARGUMENTS`. `json_ast_sql_parser_fuzzer` accepts the `CANNOT_PARSE_*` family at the JSON -> AST stage, since the dump payload readers legitimately throw them. Found by `json_ast_sql_parser_fuzzer`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…restoreFromDump Follow-up to the previous commit: the tightened `Field::restoreFromDump` now rejects a deep `Field` dump payload at the prefix check (`Field 'value' dump must start with 'Object_'`) before any recursion would happen, so the depth-guard test's expected message changes accordingly. Found by json_ast_sql_parser_fuzzer. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Workflow [PR], commit [f39a643] Summary: ✅
AI ReviewSummaryThis PR fixes the missing Findings
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit f39a643.
Changed lines: Changed C/C++ lines covered: 32/33 (96.97%) · Uncovered code |
|
I had the same three branches queued from your issue, so I am not opening a competing PR. Two things I The three new branches accept trailing garbage. if (!buf.eof())
show_error();turns it back into The dump depth guard looks unreachable after the prefix check. Two smaller notes. The changelog entry attributes |
Build profile diff (arm_release)Commit See the job log for details. |
…umed entirely Trailing bytes after the quoted value are an error like in the other branches. The dump-depth guard in the JSON AST reader is retired: after the dump prefix check a nested dump can only be declared as Array, Tuple or Map, which are read structurally and never reach `restoreFromDump`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
| UUID value; | ||
| ReadBufferFromString buf{dump.substr(prefix.length())}; | ||
| readQuoted(value, buf); | ||
| if (!buf.eof()) |
There was a problem hiding this comment.
The new buf.eof() checks close the partial-read hole for UUID / IPv4 / IPv6, but the same exact-dump invariant is still open in the sibling quoted branches above. Decimal32 / Decimal64 / Decimal128 / Decimal256 still do readQuoted(decimal, buf) and return immediately, and the plain quoted-string branch does the same. As a result, malformed payloads like Decimal32_'1.23'junk still deserialize successfully through formatQueryFromJSON, while 'abc'junk is still accepted by direct Field::restoreFromDump / custom-setting parsing.
Because this PR is tightening malformed-dump handling on the same surface, leaving the other quoted branches as partial reads keeps the contract inconsistent across dump-encoded types. Please apply the same tail check there and add at least one regression case for a Decimal* dump with trailing bytes.
|
Review follow-up landed as |
| /// Every dump-encoded type is written by `FieldVisitorDump` as `<type name>_<payload>`, so a | ||
| /// payload of a different type (or plain garbage) is rejected here with `BAD_ARGUMENTS` instead | ||
| /// of by whichever text reader `Field::restoreFromDump` happens to pick for it. | ||
| if (!dump_str.starts_with(field_type) || dump_str.size() <= field_type.size() || dump_str[field_type.size()] != '_') |
There was a problem hiding this comment.
AggregateFunctionState still is not round-trippable on this path. Field::restoreFromDump splits that payload with raw find(',') / find(')') before it parses the quoted name and data strings (src/Core/Field.cpp:1000-1013), so a valid dump such as AggregateFunctionState_('quantiles(0.5, 0.9)', 'x') is rejected because the comma inside the aggregate name is mistaken for the separator. Any serialized data containing ) fails for the same reason. Since writeFieldJSON emits AggregateFunctionState via Field::dump, formatQueryFromJSON still cannot round-trip this dump-encoded type even after the new prefix check. Please make that restoreFromDump branch parse the two quoted strings sequentially and only then verify the closing ) / EOF.
…ggregateFunctionState quote-aware
The ack commit added `if (!buf.eof()) show_error()` to the new UUID / IPv4 /
IPv6 branches, but the sibling quoted branches (Decimal32/64/128/256 and the
plain `'...'` string branch) still fell through after `readQuoted`, so dumps
like `Decimal32_'1.23'junk` or (reached via Array/Tuple/Map recursion)
`'abc'junk` were silently accepted. Add the same EOF check so the whole
`Field::dump` -> `Field::restoreFromDump` contract holds across every quoted
branch.
`AggregateFunctionState_('name', 'data')` was parsed with a raw search for
`,` / `)` before the inner strings were read. That is quote-unaware and
rejects legitimate dumps whose aggregate name contains `,` (e.g.
`quantiles(0.5, 0.9)`) or whose serialized state bytes contain `)`. Walk the
two quoted strings in order via `readQuotedString`, then require the
closing paren and EOF, so a round-trip `dump` -> `restoreFromDump` works
for any payload `FieldVisitorDump` can produce.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Review follow-up landed as EOF check on sibling quoted branches. The ack commit AggregateFunctionState_ raw-find hazard. Reworked the branch to be quote-aware: the single Regression cases added to
Plain-string trailing-junk isn't directly reachable through |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Field::restoreFromDumpnow reads theUUID_/IPv4_/IPv6_dumps thatField::dumpwrites. Previously a well-formed dump for one of these three types round-tripped asCANNOT_RESTORE_FROM_FIELD_DUMP; the additional prefix check now surfaces malformed payloads asCANNOT_PARSE_QUOTED_STRINGwith a clearer message.Documentation entry for user-facing changes
No documentation change needed.
Detailed description / Documentation
Field::dumpwritesUUID_('...'),IPv4_('...'),IPv6_('...')for the corresponding field types, butField::restoreFromDumpnever learned to read those three prefixes: any round-trip through dump/restore of a UUID or IPv4/IPv6 value producedCANNOT_RESTORE_FROM_FIELD_DUMP. Fix adds the three parsers torestoreFromDumpand prefixes the dispatch with a<type>_check so an unrelated dump is rejected withField '<name>' dump must start with '<type>_'instead of a generic parse error deeper inside.Also updates the
04320expected message (its dump-mismatch case now trips the prefix check first) and the04654depth-guard test's expected message (a deepFielddump is now rejected at the prefix check before recursion, so theField dump payload exceeds maximum AST depth limitmessage is no longer reachable in the depth case).Note:
Object_(…)andCustomType_(…)dumps still are not restorable; that is a separate follow-up (CustomTypein particular is tied to #118993 / #119643).Closes: #121023
cc @groeneai — fuzz-lab find (JSON AST fuzzer)
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121052]