Skip to content

fix: validate updater size before caching - #84

Merged
66HEX merged 3 commits into
66HEX:masterfrom
Kevinjohn:fix/updater-cache-validation
Jul 20, 2026
Merged

66HEX merged 3 commits into
66HEX:masterfrom
Kevinjohn:fix/updater-cache-validation

Conversation

@Kevinjohn

Copy link
Copy Markdown
Contributor

An updater package rejected for a size mismatch can currently be accepted from cache on the next attempt.

What changed

  • Validate both SHA-256 and sizeBytes through one shared file check.
  • Validate the .part file before moving it into the final version cache.
  • Remove an invalid final-cache entry before retrying its download.
  • Cover both repeated downloads and a pre-existing wrong-size cache entry.

Closes #83.

Observable behavior

  • Expected: both attempts reject the wrong-size package, and no final cached package remains.
  • Before: attempt 1 rejects it after promotion; attempt 2 returns Ok(UpdatePackage { ... }) from the hash-only cache path.
  • After: both attempts return the asset-size mismatch, and the invalid package is removed.

Actual screenshots

Both screenshots use macOS 26.5.2, Apple silicon, and Rust 1.95.0 with the same focused command:

cargo test -p frame-updater download_rejects_size_mismatch_on_repeated_attempts -- --nocapture

Before — base revision 04d8b08; the second attempt is accepted from cache:

Before: repeated updater attempt incorrectly passes the wrong-size cache entry

After — commit 4ba64bf; the same regression passes:

After: repeated updater attempts both reject the wrong-size package

Verification

  • cargo test --manifest-path frame-updater/Cargo.toml
  • cargo clippy --manifest-path frame-updater/Cargo.toml --all-targets --locked -- -D warnings
  • cargo xtask ci

@Kevinjohn
Kevinjohn marked this pull request as ready for review July 18, 2026 18:51
@66HEX

66HEX commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Thanks for fixing the cache-validation inconsistency.

I would like one additional updater-safety condition before merging: the download must enforce asset.size_bytes while the response body is being streamed, rather than only after the complete response has been written to disk.

At the moment, response.content_length() is used for progress reporting, but the loop can continue writing an arbitrarily large response before validate_package_file() reports the size mismatch. A compromised or misbehaving artifact host could therefore consume unbounded bandwidth and disk space even though the package is eventually rejected.

Please add the following safeguards:

  • If Content-Length is present and differs from asset.size_bytes, reject the response before writing the body.
  • Track the number of received bytes and abort before a write would exceed asset.size_bytes. This must also cover chunked responses and responses without Content-Length.
  • Remove the partial file when this limit is exceeded.
  • Add regression tests for both an oversized declared Content-Length and an oversized streamed/chunked response without a usable length header.

This behavior predates the PR, so I do not consider it a regression introduced here. However, because this change establishes the updater's size-validation behavior, I would prefer to close the remaining disk-exhaustion path in the same PR.

@66HEX
66HEX self-requested a review as a code owner July 19, 2026 17:57
@Kevinjohn

Copy link
Copy Markdown
Contributor Author

Will do - be with you after world cup final :)

@Kevinjohn

Copy link
Copy Markdown
Contributor Author

Implemented the feedback in client.rs

  • Rejects mismatched Content-Length before creating the partial file.
  • Aborts before any streamed write would exceed asset.size_bytes.
  • Removes the partial file on overflow.
  • Adds regression tests for declared-length and chunked-response overflow.

Validation passed:

  • cargo test -p frame-updater — 13 tests passed
  • cargo clippy -p frame-updater --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

@66HEX

66HEX commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Thank you for addressing the earlier updater-safety feedback. The implementation now rejects a mismatched Content-Length before writing, bounds streamed and chunked responses by the signed sizeBytes, removes the partial file on overflow, and validates the downloaded package before promoting it into the final cache.

I also verified the branch locally: all 13 frame-updater tests pass and Clippy reports no warnings.

There are two remaining follow-ups I would like to request before merging:

  1. Please preserve regression coverage for the original issue reported in [Bug]: Updater accepts cached package after size validation fails #83.

After the new Content-Length preflight check was added, download_rejects_size_mismatch_on_repeated_attempts now returns before creating or validating the .part file. This means the test would still pass if validation-before-cache-promotion were accidentally removed in the future.

Please add a test using a response without Content-Length, where:

  • the received body has a matching SHA-256;
  • the signed sizeBytes differs from the received size;
  • download() is called twice;
  • both attempts return a size mismatch;
  • neither the partial file nor the final cached package remains.

The existing Content-Length and oversized chunked-response tests should remain as separate coverage.

  1. Please check the file size before calculating its SHA-256 in validate_package_file().

The signed size is inexpensive to validate using fs::metadata(). Checking it first prevents an unexpectedly large or corrupted cached file from being read and hashed in full when it can already be rejected by size.

The current CI failure in frame-app/src/app/runtime.rs is unrelated to this pull request and has already been fixed on master. Please rebase this branch onto the latest master rather than merging master into it again.

The two feature commits are currently unsigned, while the existing merge commit is verified. Please ensure that all rewritten commits are signed and verified after the rebase. Squashing the feature work into one signed commit is also completely fine.

Thank you again for implementing the streaming safeguards. Once these follow-ups are pushed and CI passes on the current master, I will re-review the updated diff.

@Kevinjohn
Kevinjohn force-pushed the fix/updater-cache-validation branch from 77ec395 to 2a3d149 Compare July 20, 2026 11:42
@Kevinjohn

Copy link
Copy Markdown
Contributor Author

Update to PR:

  • Added the no-Content-Length, repeated-attempt regression coverage with cleanup assertions in client.rs
  • Size is now checked before SHA-256 calculation in client.rs
  • Rebased onto current master, removing the merge commit.

Process update:

  • All three commits are SSH-signed and reported verified: true by GitHub.

@66HEX 66HEX left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

All good, merging

@66HEX
66HEX merged commit 2fef9eb into 66HEX:master Jul 20, 2026
5 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.

[Bug]: Updater accepts cached package after size validation fails

2 participants