classification
Title: assertion failure in zipimporter.get_source() in case of a bad zlib.decompress()
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Oren Milman, brett.cannon
Priority: normal Keywords: patch

Created on 2017-09-27 06:24 by Oren Milman, last changed 2017-09-29 18:35 by brett.cannon. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3784 merged Oren Milman, 2017-09-27 07:21
Messages (2)
msg303100 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-27 06:24
The following code causes an assertion failure (in case there exists a
compressed zip file named 'foo.zip' with a file called 'bar.py' in it):

import zlib
import zipimport
def bad_decompress(*args):
    return None

zlib.decompress = bad_decompress
zipimport.zipimporter('foo.zip').get_source('bar')


This is because get_data() (in Modules/zipimport.c) assumes that
zlib.decompress() returned a bytes object, and returns it.
zipimport_zipimporter_get_source_impl() assumes that get_data() returned a
bytes object, and passes it to PyBytes_AS_STRING(), which asserts it is a bytes
object.
msg303351 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-09-29 18:34
New changeset 01c6a8859ef2ff5545a87cf537573bd342c848bf by Brett Cannon (Oren Milman) in branch 'master':
bpo-31602: Fix an assertion failure in zipimporter.get_source() in case of a bad zlib.decompress() (GH-3784)
https://github.com/python/cpython/commit/01c6a8859ef2ff5545a87cf537573bd342c848bf
History
Date User Action Args
2017-09-29 18:35:09brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-09-29 18:34:33brett.cannonsetmessages: + msg303351
2017-09-29 17:11:31brett.cannonsetassignee: brett.cannon

nosy: + brett.cannon
2017-09-27 07:21:47Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3769
2017-09-27 06:24:51Oren Milmancreate