A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/5ce3f10aeea711bb912e948fa5d9f63736df1327 below:

Reading malformed zipfiles no longer hangs with 100% CPU · python/cpython@5ce3f10 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+36

-0

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+36

-0

lines changed Original file line number Diff line number Diff line change

@@ -293,6 +293,36 @@ def test_read_return_size(self):

293 293

buf = fp.read(test_size)

294 294

self.assertEqual(len(buf), test_size)

295 295 296 +

def test_truncated_zipfile(self):

297 +

fp = io.BytesIO()

298 +

with zipfile.ZipFile(fp, mode='w') as zipf:

299 +

zipf.writestr('strfile', self.data, compress_type=self.compression)

300 +

end_offset = fp.tell()

301 +

zipfiledata = fp.getvalue()

302 + 303 +

fp = io.BytesIO(zipfiledata)

304 +

with zipfile.ZipFile(fp) as zipf:

305 +

with zipf.open('strfile') as zipopen:

306 +

fp.truncate(end_offset - 20)

307 +

with self.assertRaises(EOFError):

308 +

zipopen.read()

309 + 310 +

fp = io.BytesIO(zipfiledata)

311 +

with zipfile.ZipFile(fp) as zipf:

312 +

with zipf.open('strfile') as zipopen:

313 +

fp.truncate(end_offset - 20)

314 +

with self.assertRaises(EOFError):

315 +

while zipopen.read(100):

316 +

pass

317 + 318 +

fp = io.BytesIO(zipfiledata)

319 +

with zipfile.ZipFile(fp) as zipf:

320 +

with zipf.open('strfile') as zipopen:

321 +

fp.truncate(end_offset - 20)

322 +

with self.assertRaises(EOFError):

323 +

while zipopen.read1(100):

324 +

pass

325 + 296 326

def tearDown(self):

297 327

unlink(TESTFN)

298 328

unlink(TESTFN2)

@@ -389,6 +419,7 @@ def test_add_file_before_1980(self):

389 419

with zipfile.ZipFile(TESTFN2, "w") as zipfp:

390 420

self.assertRaises(ValueError, zipfp.write, TESTFN)

391 421 422 + 392 423

@requires_zlib

393 424

class DeflateTestsWithSourceFile(AbstractTestsWithSourceFile,

394 425

unittest.TestCase):

Original file line number Diff line number Diff line change

@@ -860,6 +860,8 @@ def _read2(self, n):

860 860 861 861

data = self._fileobj.read(n)

862 862

self._compress_left -= len(data)

863 +

if not data:

864 +

raise EOFError

863 865 864 866

if self._decrypter is not None:

865 867

data = bytes(map(self._decrypter, data))

Original file line number Diff line number Diff line change

@@ -36,6 +36,9 @@ Core and Builtins

36 36

Library

37 37

-------

38 38 39 +

- Issue #20078: Reading malformed zipfiles no longer hangs with 100% CPU

40 +

consumption.

41 + 39 42

- Issue #20113: os.readv() and os.writev() now raise an OSError exception on

40 43

error instead of returning -1.

41 44

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4