Skip to content

fix: validate non-empty backup paths in LocalSource::new - #627

Open
Huge wants to merge 1 commit into
rustic-rs:mainfrom
Huge:fix/localsource-empty-backup-paths
Open

Huge wants to merge 1 commit into
rustic-rs:mainfrom
Huge:fix/localsource-empty-backup-paths

Conversation

@Huge

@Huge Huge commented Oct 27, 2026

Copy link
Copy Markdown

Summary

When LocalSource::new is called with an empty backup_paths slice, indexing &backup_paths[0] panics with an out-of-bounds error (the len is 0 but the index is 0).

Root Cause & Fix

LocalSource::new assumed that backup_paths is never empty when initializing WalkBuilder::new(&backup_paths[0]).

This patch:

  • Uses backup_paths.split_first() to validate that the slice is not empty.
  • Returns a RusticError of kind ErrorKind::InvalidInput if no paths are provided.
  • Updates the documentation comments for LocalSource::new to list the empty path error condition.
  • Adds a unit test (test_local_source_new_empty_backup_paths) in crates/core/src/backend/ignore.rs ensuring an InvalidInput error is returned when backup_paths is empty.

Calling `LocalSource::new` with an empty `backup_paths` slice caused an
immediate out-of-bounds indexing panic at `&backup_paths[0]`.

Use `backup_paths.split_first()` to ensure at least one path is provided
before initializing `WalkBuilder`, returning an `InvalidInput` error
otherwise. Add a unit test verifying that empty backup paths return an
error instead of panicking.

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