From 7db5ccd30508dd158f9df18742d1ca7724d62f79 Mon Sep 17 00:00:00 2001 From: object1337 <> Date: Thu, 5 Feb 2026 17:24:40 +0100 Subject: [PATCH 1/3] Fixed vmdk thin opening when parentFileNameHint was set to full path --- dissect/hypervisor/disk/vmdk.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dissect/hypervisor/disk/vmdk.py b/dissect/hypervisor/disk/vmdk.py index 9165bb9..b448526 100644 --- a/dissect/hypervisor/disk/vmdk.py +++ b/dissect/hypervisor/disk/vmdk.py @@ -533,10 +533,12 @@ def open_parent(path: Path, filename_hint: str) -> VMDK: try: filename_hint = filename_hint.replace("\\", "/") hint_path, _, filename = filename_hint.rpartition("/") - filepath = path.joinpath(filename) + filepath = path.joinpath(filename_hint) if not filepath.exists(): - _, _, hint_path_name = hint_path.rpartition("/") - filepath = path.parent.joinpath(hint_path_name).joinpath(filename) + filepath = path.joinpath(filename) + if not filepath.exists(): + _, _, hint_path_name = hint_path.rpartition("/") + filepath = path.parent.joinpath(hint_path_name).joinpath(filename) vmdk = VMDK(filepath) except Exception as err: raise IOError(f"Failed to open parent disk with hint {filename_hint} from path {path}: {err}") From db87e70fdec7ffeb0a1b8a373b35ac6adb4d9916 Mon Sep 17 00:00:00 2001 From: object1337 <> Date: Fri, 6 Feb 2026 13:53:47 +0100 Subject: [PATCH 2/3] Added VMDK test cases in test_open_parent_all_case --- tests/disk/test_vmdk.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/disk/test_vmdk.py b/tests/disk/test_vmdk.py index 851a85c..13aea51 100644 --- a/tests/disk/test_vmdk.py +++ b/tests/disk/test_vmdk.py @@ -1,11 +1,13 @@ from __future__ import annotations import gzip +from pathlib import Path +from unittest.mock import MagicMock import pytest from dissect.hypervisor.disk.c_vmdk import c_vmdk -from dissect.hypervisor.disk.vmdk import VMDK, DiskDescriptor, ExtentDescriptor +from dissect.hypervisor.disk.vmdk import VMDK, DiskDescriptor, ExtentDescriptor, open_parent from tests._util import absolute_path @@ -203,3 +205,40 @@ def test_vmdk_extent_description(extent_description: str, expected_extents: list descriptor = DiskDescriptor.parse(extent_description) assert descriptor.extents == expected_extents + + +def test_open_parent_all_cases(monkeypatch: pytest.MonkeyPatch) -> None: + """Test open_parent handles absolute and relative filename_hint paths.""" + + # Mock Path.exists to simulate file existence + def mock_exists(path: Path) -> bool: + return str(path) in { + "/a/b/c/d.vmdk", # Case: absolute path + "base/relative/hint.vmdk", # Case: full relative path + "base/hint.vmdk", # Case: basename in same dir + "../sibling/hint.vmdk", # Case: fallback to sibling + } + + with monkeypatch.context() as m: + m.setattr("pathlib.Path.exists", mock_exists) + + # Mock VMDK to avoid real file I/O + mock_vmdk = MagicMock() + m.setattr("dissect.hypervisor.disk.vmdk.VMDK", lambda path: mock_vmdk) + mock_vmdk.path = "mocked-path" + + # Case: Absolute path — should use /a/b/c/d.vmdk directly + vmdk = open_parent(Path("base"), "/a/b/c/d.vmdk") + assert str(vmdk.path) == "mocked-path" + + # Case: Full relative path — try base/relative/hint.vmdk + vmdk = open_parent(Path("base"), "relative/hint.vmdk") + assert str(vmdk.path) == "mocked-path" + + # Case: Basename only — fall back to base/hint.vmdk + vmdk = open_parent(Path("base"), "hint.vmdk") + assert str(vmdk.path) == "mocked-path" + + # Case: Fallback to sibling — try ../sibling/hint.vmdk + vmdk = open_parent(Path("base"), "sibling/hint.vmdk") + assert str(vmdk.path) == "mocked-path" From 4dc85d1c21ba1f761b327f837029ca32ad11f36d Mon Sep 17 00:00:00 2001 From: Erik Schamper <1254028+Schamper@users.noreply.github.com> Date: Thu, 12 Feb 2026 14:05:21 +0100 Subject: [PATCH 3/3] Apply suggestions from code review --- dissect/hypervisor/disk/vmdk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dissect/hypervisor/disk/vmdk.py b/dissect/hypervisor/disk/vmdk.py index b448526..8af096a 100644 --- a/dissect/hypervisor/disk/vmdk.py +++ b/dissect/hypervisor/disk/vmdk.py @@ -533,9 +533,9 @@ def open_parent(path: Path, filename_hint: str) -> VMDK: try: filename_hint = filename_hint.replace("\\", "/") hint_path, _, filename = filename_hint.rpartition("/") - filepath = path.joinpath(filename_hint) + filepath = path.joinpath(filename) if not filepath.exists(): - filepath = path.joinpath(filename) + filepath = path.joinpath(filename_hint) if not filepath.exists(): _, _, hint_path_name = hint_path.rpartition("/") filepath = path.parent.joinpath(hint_path_name).joinpath(filename)