Skip to content

fix(json): return a parse error for a decimal precision above 38 - #1010

Closed
LuciferYang wants to merge 1 commit into
apache:mainfrom
LuciferYang:fix/sweep-11-decimal-parse-range-exception
Closed

LuciferYang wants to merge 1 commit into
apache:mainfrom
LuciferYang:fix/sweep-11-decimal-parse-range-exception

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

What

TypeFromJson built DecimalType straight from the regex-parsed precision. The constructor throws IcebergError for a precision above 38, so a type string such as "decimal(39, 2)" threw out of a Result-returning parser instead of producing a JsonParseError. This reaches table-metadata reads and REST bodies that carry a schema.

Closes #1009.

How

Return JsonParseError when the parsed precision exceeds DecimalType::kMaxPrecision, before the type is constructed. The regex only captures digits and ParseNumber rejects int32 overflow, so no lower-bound check is needed.

Testing

TypeJsonTest.FromJsonOutOfRangeDecimalPrecisionIsParseError parses "decimal(39, 2)" and expects kJsonParseError. Without the fix it fails with DecimalType: precision must be in [0, 38], was 39 thrown in the test body.

…alType

TypeFromJson's decimal branch constructed DecimalType directly after
regex-parsing the numbers; the constructor throws IcebergError via
CHECK_OR_DIE when precision exceeds the supported maximum of 38, so a
schema string like "decimal(39, 2)" escaped the Result error contract
as an uncaught exception. Check the range first and return
JsonParseError, keeping malformed schema JSON inside the parse-error
model.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 05:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zhjwpku zhjwpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Just wondering, was this discovered through cross-engine testing?

@LuciferYang

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @zhjwpku. To answer your question: no, this came from reading the parser, not from a cross-engine run. Looking at it again, the only input that reaches this path is a metadata file with a decimal precision above 38, which no conforming writer produces, so it hardens against malformed metadata rather than fixing something users run into. I'm closing it to keep the focus on reproducible issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: TypeFromJson throws an uncaught exception on a decimal precision above 38

3 participants