Skip to content

fix: discover_local_files infinite loop on symlink cycles #14

@noahgift

Description

@noahgift

Bug

discover_local_files() in src/bin/copia.rs:227 uses path.is_dir() which follows symlinks. A symlink pointing to an ancestor directory creates an infinite traversal loop, consuming unbounded memory.

Reproduction

mkdir -p /tmp/copia-test/a/b
ln -s /tmp/copia-test /tmp/copia-test/a/b/loop
copia sync /tmp/copia-test user@host:/dest
# Hangs forever, OOM

Fix

Skip symlinked directories:

if path.is_dir() && !path.is_symlink() {
    dirs.push(path);
}

Or track visited inodes with a HashSet<(u64, u64)> for (dev, ino) pairs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions