@@ -2417,10 +2417,10 @@ def test_decompress_without_3rd_party_library(self):
2417
2417
self .assertRaises (RuntimeError , zf .extract , 'a.txt' )
2418
2418
2419
2419
@requires_zlib ()
2420
- def test_full_overlap (self ):
2420
+ def test_full_overlap_different_names (self ):
2421
2421
data = (
2422
2422
b'PK\x03 \x04 \x14 \x00 \x00 \x00 \x08 \x00 \xa0 lH\x05 \xe2 \x1e '
2423
- b'8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 a \xed '
2423
+ b'8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 b \xed '
2424
2424
b'\xc0 \x81 \x08 \x00 \x00 \x00 \xc0 0\xd6 \xfb K\\ d\x0b `P'
2425
2425
b'K\x01 \x02 \x14 \x00 \x14 \x00 \x00 \x00 \x08 \x00 \xa0 lH\x05 \xe2 '
2426
2426
b'\x1e 8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 \x00 '
@@ -2441,9 +2441,37 @@ def test_full_overlap(self):
2441
2441
self .assertEqual (zi .header_offset , 0 )
2442
2442
self .assertEqual (zi .compress_size , 16 )
2443
2443
self .assertEqual (zi .file_size , 1033 )
2444
- self .assertEqual (len (zipf .read ('a ' )), 1033 )
2444
+ self .assertEqual (len (zipf .read ('b ' )), 1033 )
2445
2445
with self .assertRaisesRegex (zipfile .BadZipFile , 'File name.*differ' ):
2446
- zipf .read ('b' )
2446
+ zipf .read ('a' )
2447
+
2448
+ @requires_zlib ()
2449
+ def test_full_overlap_same_name (self ):
2450
+ data = (
2451
+ b'PK\x03 \x04 \x14 \x00 \x00 \x00 \x08 \x00 \xa0 lH\x05 \xe2 \x1e '
2452
+ b'8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 a\xed '
2453
+ b'\xc0 \x81 \x08 \x00 \x00 \x00 \xc0 0\xd6 \xfb K\\ d\x0b `P'
2454
+ b'K\x01 \x02 \x14 \x00 \x14 \x00 \x00 \x00 \x08 \x00 \xa0 lH\x05 \xe2 '
2455
+ b'\x1e 8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 \x00 '
2456
+ b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 aPK'
2457
+ b'\x01 \x02 \x14 \x00 \x14 \x00 \x00 \x00 \x08 \x00 \xa0 lH\x05 \xe2 \x1e '
2458
+ b'8\xbb \x10 \x00 \x00 \x00 \t \x04 \x00 \x00 \x01 \x00 \x00 \x00 \x00 \x00 '
2459
+ b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 aPK\x05 '
2460
+ b'\x06 \x00 \x00 \x00 \x00 \x02 \x00 \x02 \x00 ^\x00 \x00 \x00 /\x00 \x00 '
2461
+ b'\x00 \x00 \x00 '
2462
+ )
2463
+ with zipfile .ZipFile (io .BytesIO (data ), 'r' ) as zipf :
2464
+ self .assertEqual (zipf .namelist (), ['a' , 'a' ])
2465
+ self .assertEqual (len (zipf .infolist ()), 2 )
2466
+ zi = zipf .getinfo ('a' )
2467
+ self .assertEqual (zi .header_offset , 0 )
2468
+ self .assertEqual (zi .compress_size , 16 )
2469
+ self .assertEqual (zi .file_size , 1033 )
2470
+ self .assertEqual (len (zipf .read ('a' )), 1033 )
2471
+ self .assertEqual (len (zipf .read (zi )), 1033 )
2472
+ self .assertEqual (len (zipf .read (zipf .infolist ()[1 ])), 1033 )
2473
+ with self .assertRaisesRegex (zipfile .BadZipFile , 'Overlapped entries' ):
2474
+ zipf .read (zipf .infolist ()[0 ])
2447
2475
2448
2476
@requires_zlib ()
2449
2477
def test_quoted_overlap (self ):
0 commit comments