Skip to content

Commit

Permalink
fix(extractor): do not use Path.readlink to check for empty targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
qkaiser committed Dec 9, 2024
1 parent 162cca4 commit 8c778cd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions unblob/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8c778cd

Please sign in to comment.