Unzipping directory structure with python

后端 未结 9 1563
闹比i
闹比i 2020-12-13 00:56

I have a zip file which contains the following directory structure:

dir1\\dir2\\dir3a
dir1\\dir2\\dir3b

I\'m trying to unzip it and maintai

9条回答
  •  囚心锁ツ
    2020-12-13 01:10

    Don't trust extract() or extractall().

    These methods blindly extract files to the paths given in their filenames. But ZIP filenames can be anything at all, including dangerous strings like “x/../../../etc/passwd”. Extract such files and you could have just compromised your entire server.

    Maybe this should be considered a reportable security hole in Python's zipfile module, but any number of zip-dearchivers have exhibited the exact same behaviour in the past. To unarchive a ZIP file with folder structure safely you need in-depth checking of each file path.

提交回复
热议问题