unblob icon indicating copy to clipboard operation
unblob copied to clipboard

tar extractor returns non-zero exit code when attempting to create device files

Open qkaiser opened this issue 2 years ago • 0 comments

Python3 builtin tar extractor does not pay attention to the current privilege level and will try to create device files even if we don't have elevated privileges:

2022-10-03 07:44.28 [error    ] 2022-10-03 07:44.28 [error    ] Extract command failed         command=python3 -m tarfile -e /results/extraction/firmware_extract/40-392835312.bzip2_extract/40-392835312_extract/system_2.0.0.0.tbz2_extract/system_2.0.0.0.tar /results/extraction/firmware_extract/40-392835312.bzip2_extract/40-392835312_extract/system_2.0.0.0.tbz2_extract/system_2.0.0.0.tar_extract exit_code=0x1 pid=15 severity=<Severity.WARNING: 'WARNING'> stderr=Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.10/tarfile.py", line 2614, in <module>
    main()
  File "/usr/local/lib/python3.10/tarfile.py", line 2576, in main
    tf.extractall(path=curdir)
  File "/usr/local/lib/python3.10/tarfile.py", line 2059, in extractall
    self.extract(tarinfo, path, set_attrs=not tarinfo.isdir(),
  File "/usr/local/lib/python3.10/tarfile.py", line 2100, in extract
    self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
  File "/usr/local/lib/python3.10/tarfile.py", line 2179, in _extract_member
    self.makedev(tarinfo, targetpath)
  File "/usr/local/lib/python3.10/tarfile.py", line 2252, in makedev
    os.mknod(targetpath, mode,
PermissionError: [Errno 1] Operation not permitted

I recommend we keep the same module but call it from unblob while catching PermissionError exceptions. This way we don't have this verbose log that could make users think something went wrong.

I don't have the motivation to report this to tarfile maintainers.

qkaiser avatar Oct 04 '22 13:10 qkaiser