@@ -493,6 +493,14 @@ private int ReadingNotSupported(byte[] destination, int offset, int count)
493
493
throw new ZipException ( "The compression method for this entry is not supported" ) ;
494
494
}
495
495
496
+ /// <summary>
497
+ /// Handle attempts to read from this entry by throwing an exception
498
+ /// </summary>
499
+ private int StoredDescriptorEntry ( byte [ ] destination , int offset , int count ) =>
500
+ throw new StreamUnsupportedException (
501
+ "The combination of Stored compression method and Descriptor flag is not possible to read using ZipInputStream" ) ;
502
+
503
+
496
504
/// <summary>
497
505
/// Perform the initial read on an entry which may include
498
506
/// reading encryption headers and setting up inflation.
@@ -544,13 +552,22 @@ private int InitialRead(byte[] destination, int offset, int count)
544
552
inputBuffer . CryptoTransform = null ;
545
553
}
546
554
547
- if ( ( csize > 0 ) || ( ( flags & ( int ) GeneralBitFlags . Descriptor ) != 0 ) )
555
+ var usesDescriptor = ( flags & ( int ) GeneralBitFlags . Descriptor ) != 0 ;
556
+
557
+ if ( ( csize > 0 ) || usesDescriptor )
548
558
{
549
559
if ( ( method == CompressionMethod . Deflated ) && ( inputBuffer . Available > 0 ) )
550
560
{
551
561
inputBuffer . SetInflaterInput ( inf ) ;
552
562
}
553
563
564
+ // It's not possible to know how many bytes to read when using "Stored" compression (unless using encryption)
565
+ if ( ! entry . IsCrypted && method == CompressionMethod . Stored && usesDescriptor )
566
+ {
567
+ internalReader = StoredDescriptorEntry ;
568
+ return StoredDescriptorEntry ( destination , offset , count ) ;
569
+ }
570
+
554
571
internalReader = new ReadDataHandler ( BodyRead ) ;
555
572
return BodyRead ( destination , offset , count ) ;
556
573
}
0 commit comments