Skip to content

fix(prune): safely handle directory nodes without subtree in find_used_blobs - #587

Open
Huge wants to merge 1 commit into
rustic-rs:mainfrom
Huge:fix/prune-dir-missing-subtree
Open

Huge wants to merge 1 commit into
rustic-rs:mainfrom
Huge:fix/prune-dir-missing-subtree

Conversation

@Huge

@Huge Huge commented Oct 6, 2026

Copy link
Copy Markdown

Problem & Root Cause

In crates/core/src/commands/prune.rs, find_used_blobs iterates over tree nodes and unconditionally calls .unwrap() on node.subtree when encountering nodes of type NodeType::Dir:

NodeType::Dir => {
    _ = ids.insert(BlobId::from(*node.subtree.unwrap()), 0);
}

If a repository contains a corrupted or malformed snapshot / tree where a directory entry has subtree: None, running prune causes an unhandled panic:

called `Option::unwrap()` on a `None` value

This crashes the host application and prevents users from pruning or cleaning up the repository.

Solution

  1. Extracted node blob collection into collect_used_node_blobs and safely check node.subtree using if let Some(subtree) = node.subtree.
  2. When subtree is None, the missing subtree is safely skipped rather than panicking.
  3. Added unit tests in crates/core/src/commands/prune.rs verifying that directory nodes without a subtree do not panic and that directory nodes with a subtree are correctly recorded.

Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.

…d_blobs

In `crates/core/src/commands/prune.rs`, `find_used_blobs` unconditionally
called `.unwrap()` on `node.subtree` when iterating over `NodeType::Dir` nodes.
If a repository contains a corrupted or malformed snapshot / tree where a
directory entry has `subtree: None`, running `prune` caused an unhandled panic
(`called Option::unwrap() on a None value`).

Safely check `node.subtree` with `if let Some(subtree)` when collecting used
blobs, ignoring missing directory subtrees rather than crashing. Also add unit
regression tests verifying that directory nodes with and without subtree IDs
are handled gracefully.

Reported-by: BS.ehlas.cz
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.

1 participant