@@ -228,15 +228,15 @@ def __init__(self, filename_or_obj):
228
228
self ._mini_sector_size = 1 << mini_sector_size
229
229
if not (128 <= self ._normal_sector_size <= 1048576 ):
230
230
warnings .warn (
231
+ CompoundFileSectorSizeWarning (
231
232
'FAT sector size is silly (%d bytes), '
232
- 'assuming 512' % self ._normal_sector_size ,
233
- CompoundFileSectorSizeWarning )
233
+ 'assuming 512' % self ._normal_sector_size ))
234
234
self ._normal_sector_size = 512
235
235
if not (8 <= self ._mini_sector_size < self ._normal_sector_size ):
236
236
warnings .warn (
237
+ CompoundFileSectorSizeWarning (
237
238
'mini FAT sector size is silly (%d bytes), '
238
- 'assuming 64' % self ._mini_sector_size ,
239
- CompoundFileSectorSizeWarning )
239
+ 'assuming 64' % self ._mini_sector_size ))
240
240
self ._mini_sector_size = 64
241
241
self ._normal_sector_format = st .Struct (
242
242
native_str ('<%dL' % (self ._normal_sector_size // 4 )))
@@ -249,40 +249,40 @@ def __init__(self, filename_or_obj):
249
249
if self ._dll_version == 3 :
250
250
if self ._normal_sector_size != 512 :
251
251
warnings .warn (
252
+ CompoundFileSectorSizeWarning (
252
253
'unexpected sector size in v3 file '
253
- '(%d)' % self ._normal_sector_size ,
254
- CompoundFileSectorSizeWarning )
254
+ '(%d)' % self ._normal_sector_size ))
255
255
if self ._dir_sector_count != 0 :
256
256
warnings .warn (
257
+ CompoundFileHeaderWarning (
257
258
'directory chain sector count is non-zero '
258
- '(%d)' % self ._dir_sector_count ,
259
- CompoundFileHeaderWarning )
259
+ '(%d)' % self ._dir_sector_count ))
260
260
elif self ._dll_version == 4 :
261
261
if self ._normal_sector_size != 4096 :
262
262
warnings .warn (
263
+ CompoundFileSectorSizeWarning (
263
264
'unexpected sector size in v4 file '
264
- '(%d)' % self ._normal_sector_size ,
265
- CompoundFileSectorSizeWarning )
265
+ '(%d)' % self ._normal_sector_size ))
266
266
else :
267
267
raise CompoundFileVersionError (
268
268
'unsupported DLL version (%d)' % self ._dll_version )
269
269
if self ._mini_sector_size != 64 :
270
270
warnings .warn (
271
+ CompoundFileSectorSizeWarning (
271
272
'unexpected mini sector size '
272
- '(%d)' % self ._mini_sector_size ,
273
- CompoundFileSectorSizeWarning )
273
+ '(%d)' % self ._mini_sector_size ))
274
274
if uuid != (b'\0 ' * 16 ):
275
275
warnings .warn (
276
- 'CLSID of compound file is non-zero (%r)' % uuid ,
277
- CompoundFileHeaderWarning )
276
+ CompoundFileHeaderWarning (
277
+ 'CLSID of compound file is non-zero (%r)' % uuid ) )
278
278
if txn_signature != 0 :
279
279
warnings .warn (
280
- 'transaction signature is non-zero '
281
- '(%d)' % txn_signature , CompoundFileHeaderWarning )
280
+ CompoundFileHeaderWarning (
281
+ 'transaction signature is non-zero (%d)' % txn_signature ) )
282
282
if unused != (b'\0 ' * 6 ):
283
283
warnings .warn (
284
- 'unused header bytes are non-zero '
285
- '(%r)' % unused , CompoundFileHeaderWarning )
284
+ CompoundFileHeaderWarning (
285
+ 'unused header bytes are non-zero (%r)' % unused ) )
286
286
self ._file_size = self ._mmap .size ()
287
287
self ._header_size = max (self ._normal_sector_size ,512 )
288
288
self ._max_sector = (self ._file_size - self ._header_size )// self ._normal_sector_size
@@ -348,8 +348,7 @@ def _load_master_fat(self):
348
348
# Note: when reading the master-FAT we deliberately disregard the
349
349
# master-FAT sector count read from the header as implementations may
350
350
# set this incorrectly. Instead, we scan for END_OF_CHAIN (or
351
- # FREE_SECTOR) in the DIFAT after each read and stop when we find it.
352
- # In order to avoid infinite loops (in the case of a stupid or
351
+ # FREE_SECTOR) in the DIFAT after each read and stop when we find it. # In order to avoid infinite loops (in the case of a stupid or
353
352
# malicious file) we keep track of each sector we seek to and quit in
354
353
# the event of a repeat
355
354
self ._master_fat = array (native_str ('L' ))
@@ -366,17 +365,18 @@ def _load_master_fat(self):
366
365
sector = self ._master_first_sector
367
366
if count == 0 and sector == FREE_SECTOR :
368
367
warnings .warn (
368
+ CompoundFileMasterFatWarning (
369
369
'DIFAT extension pointer is FREE_SECTOR, assuming no '
370
- 'extension' , CompoundFileMasterFatWarning )
370
+ 'extension' ) )
371
371
sector = END_OF_CHAIN
372
372
elif count == 0 and sector != END_OF_CHAIN :
373
373
warnings .warn (
374
- 'DIFAT extension pointer with zero count' ,
375
- CompoundFileMasterFatWarning )
374
+ CompoundFileMasterFatWarning (
375
+ 'DIFAT extension pointer with zero count' ) )
376
376
elif count != 0 and sector == END_OF_CHAIN :
377
377
warnings .warn (
378
- 'DIFAT chained from header, or incorrect '
379
- 'count' , CompoundFileMasterFatWarning )
378
+ CompoundFileMasterFatWarning (
379
+ 'DIFAT chained from header, or incorrect count' ) )
380
380
sector = self ._master_fat .pop ()
381
381
382
382
while True :
@@ -387,20 +387,20 @@ def _load_master_fat(self):
387
387
break
388
388
elif value == FREE_SECTOR :
389
389
warnings .warn (
390
- 'DIFAT terminated by FREE_SECTOR' ,
391
- CompoundFileMasterFatWarning )
390
+ CompoundFileMasterFatWarning (
391
+ 'DIFAT terminated by FREE_SECTOR' ) )
392
392
value = END_OF_CHAIN
393
393
break
394
394
elif self ._max_sector < value <= MAX_NORMAL_SECTOR :
395
395
warnings .warn (
396
- 'sector in DIFAT chain beyond file end '
397
- '(%d)' % value , CompoundFileMasterFatWarning )
396
+ CompoundFileMasterFatWarning (
397
+ 'sector in DIFAT chain beyond file end (%d)' % value ) )
398
398
value = END_OF_CHAIN
399
399
break
400
400
elif value > MAX_NORMAL_SECTOR :
401
401
warnings .warn (
402
- 'invalid special value in DIFAT chain '
403
- '(%d)' % value , CompoundFileMasterFatWarning )
402
+ CompoundFileMasterFatWarning (
403
+ 'invalid special value in DIFAT chain (%d)' % value ) )
404
404
if value == END_OF_CHAIN :
405
405
del self ._master_fat [index :]
406
406
break
@@ -428,18 +428,18 @@ def _load_master_fat(self):
428
428
429
429
if count > 0 :
430
430
warnings .warn (
431
- 'DIFAT end encountered early (expected %d more '
432
- 'sectors)' % count , CompoundFileMasterFatWarning )
431
+ CompoundFileMasterFatWarning (
432
+ 'DIFAT end encountered early (expected %d more sectors)' % count ) )
433
433
elif count < 0 :
434
434
warnings .warn (
435
- 'DIFAT end encountered late (overran by %d '
436
- 'sectors)' % - count , CompoundFileMasterFatWarning )
435
+ CompoundFileMasterFatWarning (
436
+ 'DIFAT end encountered late (overran by %d sectors)' % - count ) )
437
437
self ._master_sector_count -= count
438
438
if len (self ._master_fat )!= self ._normal_sector_count :
439
439
warnings .warn (
440
+ CompoundFileMasterFatWarning (
440
441
'DIFAT length does not match FAT sector count '
441
- '(%d != %d)' % (len (self ._master_fat ),self ._normal_sector_count ),
442
- CompoundFileMasterFatWarning )
442
+ '(%d != %d)' % (len (self ._master_fat ),self ._normal_sector_count )))
443
443
self ._normal_sector_count = len (self ._master_fat )
444
444
return sectors
445
445
@@ -465,22 +465,26 @@ def _load_normal_fat(self, master_sectors):
465
465
for master_sector in master_sectors :
466
466
if self ._normal_fat [master_sector ]!= MASTER_FAT_SECTOR :
467
467
warnings .warn (
468
+ CompoundFileMasterSectorWarning (
468
469
'DIFAT sector %d marked incorrectly in FAT '
469
470
'(%d != %d)' % (
470
471
master_sector ,
471
472
self ._normal_fat [master_sector ],
472
473
MASTER_FAT_SECTOR ,
473
- ),CompoundFileMasterSectorWarning )
474
+ )
475
+ ))
474
476
self ._normal_fat [master_sector ]= MASTER_FAT_SECTOR
475
477
for normal_sector in self ._master_fat :
476
478
if self ._normal_fat [normal_sector ]!= NORMAL_FAT_SECTOR :
477
479
warnings .warn (
480
+ CompoundFileNormalSectorWarning (
478
481
'FAT sector %d marked incorrectly in FAT '
479
482
'(%d != %d)' % (
480
483
normal_sector ,
481
484
self ._normal_fat [normal_sector ],
482
485
NORMAL_FAT_SECTOR ,
483
- ),CompoundFileNormalSectorWarning )
486
+ )
487
+ ))
484
488
self ._normal_fat [normal_sector ]= NORMAL_FAT_SECTOR
485
489
486
490
def _load_mini_fat (self ):
@@ -498,14 +502,14 @@ def _load_mini_fat(self):
498
502
# is shorter)
499
503
if self ._mini_first_sector == FREE_SECTOR :
500
504
warnings .warn (
501
- 'mini FAT first sector set to FREE_SECTOR' ,
502
- CompoundFileMiniFatWarning )
505
+ CompoundFileMiniFatWarning (
506
+ 'mini FAT first sector set to FREE_SECTOR' ) )
503
507
self ._mini_first_sector = END_OF_CHAIN
504
508
elif self ._max_sector < self ._mini_first_sector <= MAX_NORMAL_SECTOR :
505
509
warnings .warn (
510
+ CompoundFileMiniFatWarning (
506
511
'mini FAT first sector beyond file end '
507
- '(%d)' % self ._mini_first_sector ,
508
- CompoundFileMiniFatWarning )
512
+ '(%d)' % self ._mini_first_sector ))
509
513
self ._mini_first_sector = END_OF_CHAIN
510
514
if self ._mini_first_sector != END_OF_CHAIN :
511
515
with CompoundFileNormalStream (