Skip to content

restore panics instead of returning an error when a file cannot be written or a pack read fails #593

Done

Description

@stefanwichmann

Summary

restore_contents (crates/core/src/commands/restore.rs) unwraps the results of destination writes and pack reads inside rayon worker closures. A file the destination cannot create or write, or a pack read that fails, panics a worker thread instead of returning an error. The caller loses the original error and every file not yet written. A host that does not catch the panic aborts.

Seen on rustic_core 0.13.0, and still present on main at 647d00f:

  • restore.rs:624: be.read_partial(FileType::Pack, &pack_id, false, offset, length).unwrap()
  • restore.rs:658: dest.set_length(path, filesize).unwrap()
  • restore.rs:663: dest.write_at(path, start, &data).unwrap()

Reproduction (macOS, APFS)

APFS refuses a file name that is not valid UTF-8 with EILSEQ (errno 92). A snapshot taken on Linux can hold such a name.

  1. Write a snapshot holding a file named b"not-utf8-\xff". (We used Repository::archive with a ReadSource that renames one LocalSource entry and its Node.)
  2. Restore it on macOS to an APFS folder with prepare_restore and restore.

prepare_restore succeeds. restore then panics in a worker:

thread '<unnamed>' panicked at rustic_core-0.13.0/src/commands/restore.rs:658:69:
called `Result::unwrap()` on an `Err` value: OpeningFileFailed(Os { code: 92, kind: Uncategorized, message: "Illegal byte sequence" })

The same happens for any file the destination refuses, for example a read-only folder or a full volume. Line 624 does the same for a pack read that fails partway, for example a dropped connection or a missing pack.

Expected

A failed write or read returns an error the caller can see, carrying the path and the source error. That lets the caller report it, as restic restore does: it names a file it cannot create and goes on with the rest. Returning it from restore would be enough, even if the restore then stops.

Context

We embed rustic_core in a library and run restore under catch_unwind. That keeps the host alive, but the error is gone by then. Our workarounds:

  • We filter names the destination cannot hold before calling prepare_restore.
  • We wrap the backend to keep the first failed pack read.

Both would go away if these errors were returned.

Activity

  1. added
    S-triage
    on Oct 8, 2026
  2. stefanwichmann commented on Oct 8, 2026

    @stefanwichmann
    ContributorAuthor

    One more of the same kind in restore_contents, at restore.rs:643 on main: be.read_encrypted_from_partial(&read_data[start..end], bl.uncompressed_length).unwrap(). A pack whose bytes changed but kept their length fails its MAC check here and panics a worker. Returning that error would let a caller report it as damaged data instead of an unexpected stop.

  3. AlphaJack commented on Oct 15, 2026

    @AlphaJack
    Contributor

    Also on Linux a restore over a read-only file panics at restore.rs:658 with EACCES as an unprivileged user:

    #!/bin/sh
    T=$(mktemp -d)
    export HOME=$T XDG_CONFIG_HOME=$T/config XDG_CACHE_HOME=$T/cache RUSTIC_NO_PROGRESS=true
    mkdir -p "$T/data" "$T/out"
    echo hello > "$T/data/a.txt"
    echo old > "$T/out/a.txt"
    rustic -r $T/repo --password test init
    rustic -r $T/repo --password test backup "$T/data"
    chmod 444 "$T/out/a.txt"
    chmod 555 "$T/out"
    RUST_BACKTRACE=1 rustic -r $T/repo --password test restore "latest:$T/data" "$T/out"; echo "exit: $?"
    chmod -R u+w "$T"
    rm -rf "$T"

    Output:

    Files:  0 to restore, 0 unchanged, 0 verified, 1 to modify, 0 additional
    Dirs:   0 to restore, 0 to modify, 0 additional
    [INFO] total restore size: 6 B
    
    thread '<unnamed>' (3441148) panicked at /usr/src/debug/rustic/registry/src/index.crates.io-1949cf8c6b5b557f/rustic_core-0.13.0/src/commands/restore.rs:658:69:
    called `Result::unwrap()` on an `Err` value: OpeningFileFailed(Os { code: 13, kind: PermissionDenied, message: "Permission denied" })
    stack backtrace:
       0:     0x560677e56ad9 - <unknown>
       #      [...]
      18:     0x7ff313b2072c - <unknown>
      19:                0x0 - <unknown>
    Abgebrochen                (Speicherabzug geschrieben) RUST_BACKTRACE=full rustic -r $T/repo --password test restore "latest:$T/data" "$T/out"
    exit: 134
    
  4. added a commit that references this issue on Nov 30, 2026
    fe80ab1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions