fix: avoid panic in snapshot summary update_totals on malformed values#161
Merged
Merged
Conversation
Previously update_totals called .unwrap() when parsing snapshot summary
properties (total-*, added-*, removed-*) as u64. A value written by a
non-Rust writer that exceeds u64::MAX (or is otherwise malformed) caused
ParseIntError { kind: PosOverflow } and aborted the writer. The same
function used checked subtraction (`new_total -= value`), which could
panic in debug builds on a removed > previous + added skew from corrupt
history.
Replace both with parse-or-zero + saturating arithmetic so a single
corrupt prior summary cannot indefinitely break compaction / commit for
a table. Behavior matches Java Iceberg's SnapshotSummary, which treats
missing or unparseable values as 0.
Add tests for the three failure modes (overflowing previous total,
removed > previous + added, non-numeric value).
Collaborator
|
Thanks for the fix. One concern: |
…values `update_snapshot_summaries` routes the truncate-overwrite path through `truncate_table_summary`, which parsed previous-summary totals via `get_prop` as `i32` and propagated `ParseIntError` with `?`. The caller then did `.map_err(...).unwrap()`, so a malformed, empty, or u64-overflowing previous total (legal in summaries written by other engines) would panic the writer. The `i32` ceiling was also too narrow for real-world `TOTAL_FILE_SIZE` values (~2.1 GB), making the panic reachable on perfectly valid input. Apply the same parse-or-zero / non-panicking policy already used in `update_totals`: - Replace `get_prop` with `previous_total_or_zero`, which parses as `u64` and returns 0 for missing, malformed, or overflowing values. - Make `truncate_table_summary` infallible and collapse the six near-identical blocks into a single (total, removed) loop. - Drop the `.map_err(...).unwrap()` in `update_snapshot_summaries`. Add a test that drives the full truncate-overwrite path with a previous summary containing garbage, empty, u64-overflowing, i32-overflowing (but valid u64), well-formed, and missing totals. Asserts no panic, all totals reset to 0, malformed/missing previous totals do not emit a bogus removed_* counter, and well-formed totals (including the value that would have broken the old i32 parser) still flow into removed_*.
Collaborator
Author
|
@chenzl25 it should be fixed now, thanks |
amitgilad3
pushed a commit
to lakeops-org/iceberg-rust-risingwave
that referenced
this pull request
Jun 4, 2026
risingwavelabs#161) * fix: avoid panic in snapshot summary update_totals on malformed values Previously update_totals called .unwrap() when parsing snapshot summary properties (total-*, added-*, removed-*) as u64. A value written by a non-Rust writer that exceeds u64::MAX (or is otherwise malformed) caused ParseIntError { kind: PosOverflow } and aborted the writer. The same function used checked subtraction (`new_total -= value`), which could panic in debug builds on a removed > previous + added skew from corrupt history. Replace both with parse-or-zero + saturating arithmetic so a single corrupt prior summary cannot indefinitely break compaction / commit for a table. Behavior matches Java Iceberg's SnapshotSummary, which treats missing or unparseable values as 0. Add tests for the three failure modes (overflowing previous total, removed > previous + added, non-numeric value). * fix: avoid panic in snapshot summary truncate overwrite on malformed values `update_snapshot_summaries` routes the truncate-overwrite path through `truncate_table_summary`, which parsed previous-summary totals via `get_prop` as `i32` and propagated `ParseIntError` with `?`. The caller then did `.map_err(...).unwrap()`, so a malformed, empty, or u64-overflowing previous total (legal in summaries written by other engines) would panic the writer. The `i32` ceiling was also too narrow for real-world `TOTAL_FILE_SIZE` values (~2.1 GB), making the panic reachable on perfectly valid input. Apply the same parse-or-zero / non-panicking policy already used in `update_totals`: - Replace `get_prop` with `previous_total_or_zero`, which parses as `u64` and returns 0 for missing, malformed, or overflowing values. - Make `truncate_table_summary` infallible and collapse the six near-identical blocks into a single (total, removed) loop. - Drop the `.map_err(...).unwrap()` in `update_snapshot_summaries`. Add a test that drives the full truncate-overwrite path with a previous summary containing garbage, empty, u64-overflowing, i32-overflowing (but valid u64), well-formed, and missing totals. Asserts no panic, all totals reset to 0, malformed/missing previous totals do not emit a bogus removed_* counter, and well-formed totals (including the value that would have broken the old i32 parser) still flow into removed_*.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes are included in this PR?
Fixes a panic in iceberg::spec::snapshot_summary::update_totals that aborts any writer attempting to commit against a table whose snapshot summary contains a value that does not parse cleanly into a u64.
The function previously did:
.map_or(0, |value| value.parse::().unwrap()) // previous total
.map(|value| value.parse::().unwrap()) // added / removed
new_total -= value; // unchecked subtraction
Three latent panics in one function:
This PR replaces all three with parse-or-zero (unwrap_or(0)) plus saturating_add / saturating_sub, factored through a small local parse_or_zero helper. Semantics now match Java Iceberg's SnapshotSummary, which treats missing or unparseable values as 0. A single corrupt prior summary can no longer indefinitely break commits for a table.
No public API change; update_totals is a private free function and its caller (update_snapshot_summaries) is unchanged.
Are these changes tested?
Yes — three new unit tests in crates/iceberg/src/spec/snapshot_summary.rs::tests, plus the five existing tests in the same module continue to pass:
test_update_totals_handles_overflowing_previous_total — seeds total-files-size with "99999999999999999999" (> u64::MAX). Previously panicked; now resets the overflowing total to 0 and applies added cleanly.
test_update_totals_saturates_on_underflow — removed=100, previous=5, added=1 previously panicked on new_total -= value; now saturates to 0.
test_update_totals_treats_malformed_value_as_zero — "garbage" and "" are accepted as 0 instead of panicking.
cargo test -p iceberg --lib spec::snapshot_summary::
test result: ok. 8 passed; 0 failed; 0 ignored
cargo fmt and cargo clippy -p iceberg --lib --tests --no-deps are clean on the touched file.