-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I have encountered the following error:
Analyzing snapshots/snapshot-ubuntu_2204-d636403018fe4e7da5f32fbad88b9ecc.qcow2
Traceback (most recent call last):
File "/home/andreia/mip/.venv/lib/python3.12/site-packages/dissect/target/container.py", line 236, in open
return container(item, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andreia/mip/.venv/lib/python3.12/site-packages/dissect/target/helpers/lazy.py", line 68, in __call__
return self._load()(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andreia/mip/.venv/lib/python3.12/site-packages/dissect/target/containers/qcow2.py", line 25, in __init__
self.qcow2 = qcow2.QCow2(fh, data_file, backing_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andreia/mip/.venv/lib/python3.12/site-packages/dissect/hypervisor/disk/qcow2.py", line 135, in __init__
self.backing_file = self._open_backing_file(backing_file, allow_no_backing_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andreia/mip/.venv/lib/python3.12/site-packages/dissect/hypervisor/disk/qcow2.py", line 224, in _open_backing_file
if (backing_file_path := self.path.with_name(self.auto_backing_file)).exists():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/pathlib.py", line 634, in with_name
raise ValueError("Invalid name %r" % (name))
ValueError: Invalid name '/home/andreia/mip/snapshots/ubuntu-22.04-packer.qcow2'
I've also found the culprit - currently, the code is designed to force the (auto-)backing file and snapshot file to be in the same directory [1], which is not always the case:
https://github.com/fox-it/dissect.hypervisor/blob/main/dissect/hypervisor/disk/qcow2.py#L191
QCOW2 images allow relative (./backing_file.qcow2) or absolute paths (/home/user/backing_file.qcow2) for the backing file (my use case requires this, hence how I've bumped into the error).
First of all, I am wandering if I am missing something from the bigger picture because I don't really get why do you sanitize auto_backing_file by callling with_name(auto_backing_file).
Are there any higher constraints for using that self.path.with_name(auto_backing_file)?
My suggestion to fix this would be something like:
if backing_file is None:
if self.path:
auto_backing = Path(self.auto_backing_file)
if auto_backing.is_absolute():
backing_file_path = auto_backing
else:
backing_file_path = self.path.with_name(self.auto_backing_file)
if backing_file_path.exists():
backing_file = backing_file_path.open("rb")I can come back with a PR to make the fix myself, if that's okay with you