From 8c778cd7abf944a22152e74adcbd63a99e50d732 Mon Sep 17 00:00:00 2001 From: Quentin Kaiser Date: Sat, 23 Nov 2024 12:23:59 +0100 Subject: [PATCH] fix(extractor): do not use Path.readlink to check for empty targets We cannot use Path.readlink to check if the symlink target is not set (that happens with f_badsymlinks.img on Darwin systems, you need a broken filesystem and an OS that supports it). That's because Path.readlink returns a Path object with an empty name (i.e. Path("")), which is indiscernable from a symlink target that is the current directory (i.e. Path(".")). Since there is no difference between Path("") and Path("."), we can't differentiate between a symlink with an empty target and a symlink that points at the current directory. --- unblob/extractor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unblob/extractor.py b/unblob/extractor.py index e0c382f37f..8308abbce1 100644 --- a/unblob/extractor.py +++ b/unblob/extractor.py @@ -65,12 +65,13 @@ def fix_symlink(path: Path, outdir: Path, task_result: TaskResult) -> Path: path.unlink() return path - target = path.readlink() - if not target.name: + raw_target = os.readlink(path) # noqa: PTH115 + if not raw_target: logger.error("Symlink with empty target, removing.") path.unlink() return path + target = Path(raw_target) if target.is_absolute(): target = Path(target.as_posix().lstrip("/")) else: