@@ -1189,6 +1189,53 @@ def test_generated_valid_zip64_extra(self):
11891189 self .assertEqual (zinfo .header_offset , expected_header_offset )
11901190 self .assertEqual (zf .read (zinfo ), expected_content )
11911191
1192+ def test_generated_extra_in_local_entry (self ):
1193+ """Should not write duplicated or improper fields to local file entry."""
1194+ # zip64
1195+ fh = io .BytesIO ()
1196+ with zipfile .ZipFile (fh , 'w' ) as zh :
1197+ zinfo = zipfile .ZipInfo ('strfile' )
1198+ zinfo .extra = (
1199+ # zip64
1200+ struct .pack ('<HHQQ' , 0x0001 , 16 , 0 , 0 ) +
1201+ # unicode comment
1202+ struct .pack ('<HHBL5s' , 0x6375 , 10 , 1 ,
1203+ zipfile .crc32 (b'\u4e00' ), b'\u4e00' ) +
1204+ # invalid tail
1205+ b'zzz'
1206+ )
1207+ zh .writestr (zinfo , self .data )
1208+
1209+ fh .seek (zinfo .header_offset )
1210+ entry = fh .read (zh .start_dir - zinfo .header_offset - zinfo .compress_size )
1211+ header = struct .unpack_from (zipfile .structFileHeader , entry )
1212+ extra = entry [- header [zipfile ._FH_EXTRA_FIELD_LENGTH ]:]
1213+ self .assertEqual (extra , (
1214+ struct .pack ('<HHQQ' , 0x0001 , 16 , 25889 , 25889 ) +
1215+ b'zzz'
1216+ ))
1217+
1218+ # no zip64
1219+ fh = io .BytesIO ()
1220+ with zipfile .ZipFile (fh , 'w' ) as zh :
1221+ zinfo = zipfile .ZipInfo ('strfile' )
1222+ zinfo .extra = (
1223+ # zip64
1224+ struct .pack ('<HHQQ' , 0x0001 , 16 , 0 , 0 ) +
1225+ # unicode comment
1226+ struct .pack ('<HHBL5s' , 0x6375 , 10 , 1 ,
1227+ zipfile .crc32 (b'\u4e00' ), b'\u4e00' ) +
1228+ # invalid tail
1229+ b'zzz'
1230+ )
1231+ zh .writestr (zinfo , 'foo' )
1232+
1233+ fh .seek (zinfo .header_offset )
1234+ entry = fh .read (zh .start_dir - zinfo .header_offset - zinfo .compress_size )
1235+ header = struct .unpack_from (zipfile .structFileHeader , entry )
1236+ extra = entry [- header [zipfile ._FH_EXTRA_FIELD_LENGTH ]:]
1237+ self .assertEqual (extra , b'zzz' )
1238+
11921239 def test_force_zip64 (self ):
11931240 """Test that forcing zip64 extensions correctly notes this in the zip file"""
11941241
0 commit comments