@@ -39,7 +39,8 @@ def test_create_and_extract_gz(sample_dir: Path, tmp_path: Path) -> None:
3939def test_create_uncompressed (sample_dir : Path , tmp_path : Path ) -> None :
4040 archive = tmp_path / "plain.tar"
4141 create_tar (str (sample_dir ), str (archive ), compression = None )
42- with tarfile .open (str (archive ), "r" ) as tf :
42+ # Reading an archive we just wrote in this test — not untrusted input.
43+ with tarfile .open (str (archive ), "r" ) as tf : # NOSONAR python:S5042
4344 assert any (name .endswith ("a.txt" ) for name in tf .getnames ())
4445
4546
@@ -72,7 +73,8 @@ def test_extract_missing_archive_raises(tmp_path: Path) -> None:
7273
7374def test_extract_rejects_path_traversal (tmp_path : Path ) -> None :
7475 archive = tmp_path / "evil.tar"
75- with tarfile .open (str (archive ), "w" ) as tf :
76+ # Write mode; fixture builds a malicious archive to exercise the guard.
77+ with tarfile .open (str (archive ), "w" ) as tf : # NOSONAR python:S5042
7678 info = tarfile .TarInfo (name = "../escape.txt" )
7779 info .size = 0
7880 tf .addfile (info , None )
@@ -83,7 +85,8 @@ def test_extract_rejects_path_traversal(tmp_path: Path) -> None:
8385
8486def test_extract_rejects_absolute_symlink (tmp_path : Path ) -> None :
8587 archive = tmp_path / "evil.tar"
86- with tarfile .open (str (archive ), "w" ) as tf :
88+ # Write mode; fixture builds a malicious archive to exercise the guard.
89+ with tarfile .open (str (archive ), "w" ) as tf : # NOSONAR python:S5042
8790 info = tarfile .TarInfo (name = "link" )
8891 info .type = tarfile .SYMTYPE
8992 info .linkname = "/etc/passwd"
0 commit comments