#3954·PaddleSeg

[错误] paddleseg/utils/download.py 中的 tar 提取没有成员验证(路径穿越)

作者: Carlson-JLQ创建于 2026年9月20日更新于 2026年9月20日
标签bug

Locations

zzterm5zz
# paddleseg/utils/download.py:79-88
def _uncompress_file_tar(filepath, extrapath, mode="r:gz"):
    files = tarfile.open(filepath, mode)
    filelist = files.getnames()
    total_num = len(filelist)
    rootpath = filelist[0]
    for index, file in enumerate(filelist):
        files.extract(file, extrapath)      # <- no filter, no member validation
        yield total_num, index, rootpath
    files.close()

Duplicated at:

  • contrib/MedicalSeg/medicalseg/utils/download.py:85
  • contrib/MedicalSeg/tools/preprocess_utils/uncompress.py:68

Why the zip branch is fine but the tar branch is not

The zip branch (:73) uses zipfile.extract(), which is sanitized by CPython (splitdrive, strips absolute paths and ./. components, and does not create symlinks from external_attr). tarfile.extract() performs no sanitization: it accepts ../ and absolute paths, and creates symlinks/hardlinks from the archive. This is the CVE-2007-4559 class.

内容来源: PaddlePaddle/PaddleSeg