File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class GzipFile:
5555 """
5656
5757 myfileobj = None
58+ max_read_chunk = 10 * 1024 * 1024 # 10Mb
5859
5960 def __init__ (self , filename = None , mode = None ,
6061 compresslevel = 9 , fileobj = None ):
@@ -215,14 +216,14 @@ def read(self, size=-1):
215216 try :
216217 while True :
217218 self ._read (readsize )
218- readsize = readsize * 2
219+ readsize = min ( self . max_read_chunk , readsize * 2 )
219220 except EOFError :
220221 size = self .extrasize
221222 else : # just get some more of it
222223 try :
223224 while size > self .extrasize :
224225 self ._read (readsize )
225- readsize = readsize * 2
226+ readsize = min ( self . max_read_chunk , readsize * 2 )
226227 except EOFError :
227228 if size > self .extrasize :
228229 size = self .extrasize
Original file line number Diff line number Diff line change @@ -58,6 +58,29 @@ def test_append(self):
5858 f = gzip .GzipFile (self .filename , 'rb' ) ; d = f .read () ; f .close ()
5959 self .assertEqual (d , (data1 * 50 ) + (data2 * 15 ))
6060
61+ def test_many_append (self ):
62+ # Bug #1074261 was triggered when reading a file that contained
63+ # many, many members. Create such a file and verify that reading it
64+ # works.
65+ f = gzip .open (self .filename , 'wb' , 9 )
66+ f .write ('a' )
67+ f .close ()
68+ for i in range (0 ,200 ):
69+ f = gzip .open (self .filename , "ab" , 9 ) # append
70+ f .write ('a' )
71+ f .close ()
72+
73+ # Try reading the file
74+ zgfile = gzip .open (self .filename , "rb" )
75+ contents = ""
76+ while 1 :
77+ ztxt = zgfile .read (8192 )
78+ contents += ztxt
79+ if not ztxt : break
80+ zgfile .close ()
81+ self .assertEquals (contents , 'a' * 201 )
82+
83+
6184 def test_readline (self ):
6285 self .test_write ()
6386 # Try .readline() with varying line lengths
You can’t perform that action at this time.
0 commit comments