mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
[Bug #1074261, patch #1074381] Restrict the size of chunks read from the file in order to avoid overflow or huge memory consumption. Patch by Mark Eichin
This commit is contained in:
parent
a6f68e1b1f
commit
01cb47b59c
2 changed files with 26 additions and 2 deletions
|
@ -55,6 +55,7 @@ class GzipFile:
|
|||
"""
|
||||
|
||||
myfileobj = None
|
||||
max_read_chunk = 10 * 1024 * 1024 # 10Mb
|
||||
|
||||
def __init__(self, filename=None, mode=None,
|
||||
compresslevel=9, fileobj=None):
|
||||
|
@ -215,14 +216,14 @@ class GzipFile:
|
|||
try:
|
||||
while True:
|
||||
self._read(readsize)
|
||||
readsize = readsize * 2
|
||||
readsize = min(self.max_read_chunk, readsize * 2)
|
||||
except EOFError:
|
||||
size = self.extrasize
|
||||
else: # just get some more of it
|
||||
try:
|
||||
while size > self.extrasize:
|
||||
self._read(readsize)
|
||||
readsize = readsize * 2
|
||||
readsize = min(self.max_read_chunk, readsize * 2)
|
||||
except EOFError:
|
||||
if size > self.extrasize:
|
||||
size = self.extrasize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue