[New-bugs-announce] [issue30724] ZipFile.open treats directory path as empty file

Kit Yan Choi report at bugs.python.org
Wed Jun 21 12:06:47 EDT 2017


New submission from Kit Yan Choi:

Given a zipfile with the following content:

subdir/
file1.txt
subdir/file2.txt

    >>> archive = ZipFile(file_path, "r")
    >>> f = archive.open("subdir/", "r")
    >>>f.read()
    b''

It is quite odd that the subdirectory can be opened as if it was an empty file.  One would expect it to raise.

One use case is that the archive is created using shutil.make_archive, which includes the subdirectory paths in the namelist.  Upon looping ZipFile.namelist(), you end up opening a subdirectory and getting the empty content, which should have led to error and prompted the developers to filter the namelist first.

----------
messages: 296564
nosy: Kit Yan Choi
priority: normal
severity: normal
status: open
title: ZipFile.open treats directory path as empty file
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30724>
_______________________________________


More information about the New-bugs-announce mailing list