@@ -421,6 +421,75 @@ private void multiByteReadConsistentlyReturnsMinusOneAtEof(File file) throws Exc
421
421
}
422
422
}
423
423
424
+ @ Test
425
+ public void singleByteReadThrowsAtEofForCorruptedStoredEntry () throws Exception {
426
+ byte [] content ;
427
+ try (FileInputStream fs = new FileInputStream (getFile ("COMPRESS-264.zip" ))) {
428
+ content = IOUtils .toByteArray (fs );
429
+ }
430
+ // make size much bigger than entry's real size
431
+ for (int i = 17 ; i < 26 ; i ++) {
432
+ content [i ] = (byte ) 0xff ;
433
+ }
434
+ try (ByteArrayInputStream in = new ByteArrayInputStream (content );
435
+ ZipArchiveInputStream archive = new ZipArchiveInputStream (in )) {
436
+ ArchiveEntry e = archive .getNextEntry ();
437
+ try {
438
+ IOUtils .toByteArray (archive );
439
+ fail ("expected exception" );
440
+ } catch (IOException ex ) {
441
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
442
+ }
443
+ try {
444
+ archive .read ();
445
+ fail ("expected exception" );
446
+ } catch (IOException ex ) {
447
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
448
+ }
449
+ try {
450
+ archive .read ();
451
+ fail ("expected exception" );
452
+ } catch (IOException ex ) {
453
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
454
+ }
455
+ }
456
+ }
457
+
458
+ @ Test
459
+ public void multiByteReadThrowsAtEofForCorruptedStoredEntry () throws Exception {
460
+ byte [] content ;
461
+ try (FileInputStream fs = new FileInputStream (getFile ("COMPRESS-264.zip" ))) {
462
+ content = IOUtils .toByteArray (fs );
463
+ }
464
+ // make size much bigger than entry's real size
465
+ for (int i = 17 ; i < 26 ; i ++) {
466
+ content [i ] = (byte ) 0xff ;
467
+ }
468
+ byte [] buf = new byte [2 ];
469
+ try (ByteArrayInputStream in = new ByteArrayInputStream (content );
470
+ ZipArchiveInputStream archive = new ZipArchiveInputStream (in )) {
471
+ ArchiveEntry e = archive .getNextEntry ();
472
+ try {
473
+ IOUtils .toByteArray (archive );
474
+ fail ("expected exception" );
475
+ } catch (IOException ex ) {
476
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
477
+ }
478
+ try {
479
+ archive .read (buf );
480
+ fail ("expected exception" );
481
+ } catch (IOException ex ) {
482
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
483
+ }
484
+ try {
485
+ archive .read (buf );
486
+ fail ("expected exception" );
487
+ } catch (IOException ex ) {
488
+ assertEquals ("Truncated ZIP file" , ex .getMessage ());
489
+ }
490
+ }
491
+ }
492
+
424
493
private static byte [] readEntry (ZipArchiveInputStream zip , ZipArchiveEntry zae ) throws IOException {
425
494
final int len = (int )zae .getSize ();
426
495
final byte [] buff = new byte [len ];
0 commit comments