Skip to content

feat(cli): atomic publish + aliasing checks on decompress#234

Merged
polaz merged 4 commits into
mainfrom
fix/#46-cli-decompress-atomic
May 23, 2026
Merged

feat(cli): atomic publish + aliasing checks on decompress#234
polaz merged 4 commits into
mainfrom
fix/#46-cli-decompress-atomic

Conversation

@polaz

@polaz polaz commented May 23, 2026

Copy link
Copy Markdown
Member

Summary

Mirror the compress hardening (#45) onto the decompress command in cli/src/main.rs:

  • ensure_distinct_paths gates the call before any I/O — identical or hard-linked input/output paths are rejected so the decoder cannot overwrite its own source mid-stream.
  • ensure_regular_output_destination pre-flights the destination so a directory or non-regular entry fails fast (no scratch file is created on this reject path).
  • Decoded bytes stream into a scratch file via create_temporary_output_file; replace_output_file promotes it to the final destination only after a fully successful decode.
  • Decoder/copy/metadata errors remove the scratch file so partial state never lands at the final path.

Test plan

6 new tests in cli/src/main.rs::tests — nextest 20/20 pass, lint + check clean.

  • decompress_rejects_same_input_and_output_paths
  • decompress_rejects_hardlinked_output_paths (unix only)
  • decompress_reports_open_error_for_missing_input — also asserts the destination is not created
  • decompress_rejects_non_regular_output_before_creating_temp_file — also asserts no .tmp. scratch lands
  • decompress_cleans_temp_file_on_decode_failure — garbage bytes in, scratch removed, no final file
  • decompress_roundtrips_known_content — happy-path sanity

Closes #46.

Copilot AI review requested due to automatic review settings May 23, 2026 14:16
@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@polaz, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 48 minutes and 59 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0908ac68-28fe-4f8a-a054-78b454e2674a

📥 Commits

Reviewing files that changed from the base of the PR and between ee9f8ca and 76267a8.

📒 Files selected for processing (1)
  • cli/src/main.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/#46-cli-decompress-atomic

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Pull request overview

This PR mirrors the CLI compress hardening from #45 onto decompress in cli/src/main.rs, adding aliasing checks and an atomic temp-file publish flow so decompression can’t overwrite its own input and never leaves partial output behind.

Changes:

  • Add ensure_distinct_paths + ensure_regular_output_destination preflight to decompress() before any I/O.
  • Write decompressed bytes to a scratch file (create_temporary_output_file) and promote via replace_output_file only after successful decode.
  • Add decompression-focused tests covering aliasing rejection, preflight behavior, temp-file cleanup on failure, and a roundtrip sanity case.

Comment thread cli/src/main.rs Outdated
@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 23, 2026 16:29

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@polaz
polaz merged commit 967b8f7 into main May 23, 2026
23 checks passed
@polaz
polaz deleted the fix/#46-cli-decompress-atomic branch May 23, 2026 16:42
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.

feat(cli): apply aliasing checks and atomic temp-file publish to decompress

2 participants