Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attempt to load child targets when initial target loading fails #987

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dissect/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,14 @@ def _find(find_path: Path, parsed_path: Optional[urllib.parse.ParseResult]):
try:
# Attempt to load the target using this loader
target = cls._load(sub_entry, ldr)
except Exception as e:
getlogger(sub_entry).error("Failed to load target with loader %s", ldr, exc_info=e)
continue
else:
loaded = True
at_least_one_loaded = True
yield target

except Exception as e:
getlogger(sub_entry).error("Failed to load target with loader %s", ldr, exc_info=e)

if include_children:
try:
yield from target.open_children()
Expand Down
18 changes: 18 additions & 0 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,21 @@ def test_fs_mount_already_there(target_unix: Target, nr_of_fs: int) -> None:

assert f"/$fs$/fs{idx}" in target_unix.fs.mounts.keys()
assert target_unix.fs.path(f"$fs$/fs{idx}").exists()


def test_children_on_invalid_target(caplog: pytest.LogCaptureFixture, tmp_path: Path) -> None:
"""test that we don't attempt to load child targets on an invalid target"""
p = tmp_path.joinpath("empty-dir")
p.mkdir()

mock_loader = Mock()
mock_loader.find_all.return_value = [None]
mock_loader.return_value = None

with patch.object(loader, "find_loader", return_value=mock_loader):
try:
list(Target.open_all([p], include_children=True))
except Exception:
pass

assert "Failed to load child target from None" not in caplog.text
Loading