Skip to content

fix(metadata): validate format versions in JSON, builders, and properties - #1162

Merged
wgtmac merged 1 commit into
apache:mainfrom
manuzhang:fix/json-format-version-parsing
Nov 24, 2026
Merged

wgtmac merged 1 commit into
apache:mainfrom
manuzhang:fix/json-format-version-parsing

Conversation

@manuzhang

@manuzhang manuzhang commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Why

JSON conversion could truncate a fractional format-version or narrow an out-of-range integer into a supported version. For example, 2.5, 258, and -254 could all be read as version 2. A negative version supplied through a table property could also wrap into a supported version.

What

  • Decode format-version in table metadata and upgrade actions with GetJsonInteger<int8_t>. This rejects noninteger values and integers outside the int8_t range before conversion.
  • Check the supported range during metadata loading and creation, builder construction and upgrades, and property updates. The shared static TableMetadata::IsSupportedFormatVersion(int8_t) sits next to kSupportedTableFormatVersion. Callers with wider property values check that they fit in int8_t before converting.

Validation

Local validation passed for table, JSON, catalog, REST, C++20, and 17 property-update tests, plus pre-commit. REST had one existing skip.

@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch from c72f281 to e2314d9 Compare November 24, 2026 04:11
@manuzhang manuzhang changed the title fix(json): validate format versions before narrowing fix(metadata): validate format versions before narrowing Nov 24, 2026
@manuzhang manuzhang changed the title fix(metadata): validate format versions before narrowing fix(metadata): validate JSON integers and table format versions Nov 24, 2026
@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch 2 times, most recently from 7d20668 to 2518056 Compare November 24, 2026 08:13
@manuzhang
manuzhang marked this pull request as ready for review November 24, 2026 08:13
@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch 2 times, most recently from 5315069 to 9d7b757 Compare November 24, 2026 09:40
@manuzhang manuzhang changed the title fix(metadata): validate JSON integers and table format versions fix(metadata): validate table format versions before narrowing Nov 24, 2026
@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch from 9d7b757 to 33a30ba Compare November 24, 2026 09:47
@manuzhang manuzhang changed the title fix(metadata): validate table format versions before narrowing fix(metadata): validate format versions in JSON, builders, and properties Nov 24, 2026
@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch from 33a30ba to 7b8473a Compare November 24, 2026 09:51
@manuzhang
manuzhang requested review from wgtmac and zhjwpku November 24, 2026 11:31

Status TableMetadataBuilder::Impl::UpgradeFormatVersion(int8_t new_format_version) {
// Check that the new format version is supported
if (new_format_version > TableMetadata::kSupportedTableFormatVersion) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need to change here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, we didn't check whether new_format_version is less than 1 or not.

@zhjwpku zhjwpku Nov 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We checked new_format_version should be >= metadata_.format_version below, but I'm fine with this

Comment thread src/iceberg/json_serde.cc Outdated
return JsonParseError("Cannot read unsupported version: {}",
table_metadata->format_version);
ICEBERG_ASSIGN_OR_RAISE(auto format_version,
GetJsonInteger<int32_t>(json, kFormatVersion));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's int32_t here, so I think int32_t should be enough for IsSupportedFormatVersion too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In a second thought, I think it would be better to use consistently use int8_t.

…ties

Require format-version in table metadata and upgrade actions to be
an exact JSON integer in the int8_t range. Validate the supported
version when loading metadata and when building or upgrading tables.

Share the int8_t supported-range predicate across metadata parsing,
creation, builders, and property updates. Check wider property values
before narrowing so out-of-range inputs cannot alias supported versions.

Cover JSON type and range errors, invalid builder versions, and
nonpositive version properties. Update the REST parse-error assertion.

Co-authored-by: Codex <codex@openai.com>
@manuzhang
manuzhang force-pushed the fix/json-format-version-parsing branch from 7b8473a to 5f7e204 Compare November 24, 2026 13:12

@zhjwpku zhjwpku left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@wgtmac
wgtmac merged commit 31dfc3d into apache:main Nov 24, 2026
15 checks passed
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.

3 participants