@@ -1142,15 +1142,15 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1142
1142
size = localExtraData . ReadLong ( ) ;
1143
1143
compressedSize = localExtraData . ReadLong ( ) ;
1144
1144
1145
- if ( localFlags . Includes ( GeneralBitFlags . Descriptor ) )
1145
+ if ( localFlags . HasAny ( GeneralBitFlags . Descriptor ) )
1146
1146
{
1147
1147
// These may be valid if patched later
1148
- if ( ( size != - 1 ) && ( size != entry . Size ) )
1148
+ if ( ( size > 0 ) && ( size != entry . Size ) )
1149
1149
{
1150
1150
throw new ZipException ( "Size invalid for descriptor" ) ;
1151
1151
}
1152
1152
1153
- if ( ( compressedSize != - 1 ) && ( compressedSize != entry . CompressedSize ) )
1153
+ if ( ( compressedSize > 0 ) && ( compressedSize != entry . CompressedSize ) )
1154
1154
{
1155
1155
throw new ZipException ( "Compressed size invalid for descriptor" ) ;
1156
1156
}
@@ -1181,9 +1181,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1181
1181
throw new ZipException ( $ "Version required to extract this entry not supported ({ extractVersion } )") ;
1182
1182
}
1183
1183
1184
- const GeneralBitFlags notSupportedFlags = GeneralBitFlags . Patched | GeneralBitFlags . StrongEncryption |
1185
- GeneralBitFlags . EnhancedCompress | GeneralBitFlags . HeaderMasked ;
1186
- if ( localFlags . Includes ( notSupportedFlags ) )
1184
+ if ( localFlags . HasAny ( GeneralBitFlags . Patched | GeneralBitFlags . StrongEncryption | GeneralBitFlags . EnhancedCompress | GeneralBitFlags . HeaderMasked ) )
1187
1185
{
1188
1186
throw new ZipException ( $ "The library does not support the zip features required to extract this entry ({ localFlags & notSupportedFlags : F} )") ;
1189
1187
}
@@ -1215,21 +1213,21 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1215
1213
var localEncoding = _stringCodec . ZipInputEncoding ( localFlags ) ;
1216
1214
1217
1215
// Local entry flags dont have reserved bit set on.
1218
- if ( localFlags . Includes ( GeneralBitFlags . ReservedPKware4 | GeneralBitFlags . ReservedPkware14 | GeneralBitFlags . ReservedPkware15 ) )
1216
+ if ( localFlags . HasAny ( GeneralBitFlags . ReservedPKware4 | GeneralBitFlags . ReservedPkware14 | GeneralBitFlags . ReservedPkware15 ) )
1219
1217
{
1220
1218
throw new ZipException ( "Reserved bit flags cannot be set." ) ;
1221
1219
}
1222
1220
1223
1221
// Encryption requires extract version >= 20
1224
- if ( localFlags . Includes ( GeneralBitFlags . Encrypted ) && extractVersion < 20 )
1222
+ if ( localFlags . HasAny ( GeneralBitFlags . Encrypted ) && extractVersion < 20 )
1225
1223
{
1226
1224
throw new ZipException ( $ "Version required to extract this entry is too low for encryption ({ extractVersion } )") ;
1227
1225
}
1228
1226
1229
1227
// Strong encryption requires encryption flag to be set and extract version >= 50.
1230
- if ( localFlags . Includes ( GeneralBitFlags . StrongEncryption ) )
1228
+ if ( localFlags . HasAny ( GeneralBitFlags . StrongEncryption ) )
1231
1229
{
1232
- if ( ! localFlags . Includes ( GeneralBitFlags . Encrypted ) )
1230
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Encrypted ) )
1233
1231
{
1234
1232
throw new ZipException ( "Strong encryption flag set but encryption flag is not set" ) ;
1235
1233
}
@@ -1241,13 +1239,13 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1241
1239
}
1242
1240
1243
1241
// Patched entries require extract version >= 27
1244
- if ( localFlags . Includes ( GeneralBitFlags . Patched ) && extractVersion < 27 )
1242
+ if ( localFlags . HasAny ( GeneralBitFlags . Patched ) && extractVersion < 27 )
1245
1243
{
1246
1244
throw new ZipException ( $ "Patched data requires higher version than ({ extractVersion } )") ;
1247
1245
}
1248
1246
1249
1247
// Central header flags match local entry flags.
1250
- if ( ! localFlags . Equals ( ( GeneralBitFlags ) entry . Flags ) )
1248
+ if ( ( int ) localFlags != entry . Flags )
1251
1249
{
1252
1250
throw new ZipException ( $ "Central header/local header flags mismatch ({ ( GeneralBitFlags ) entry . Flags : F} vs { localFlags : F} )") ;
1253
1251
}
@@ -1264,23 +1262,23 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1264
1262
}
1265
1263
1266
1264
// Strong encryption and extract version match
1267
- if ( localFlags . Includes ( GeneralBitFlags . StrongEncryption ) )
1265
+ if ( localFlags . HasAny ( GeneralBitFlags . StrongEncryption ) )
1268
1266
{
1269
1267
if ( extractVersion < 62 )
1270
1268
{
1271
1269
throw new ZipException ( "Strong encryption flag set but version not high enough" ) ;
1272
1270
}
1273
1271
}
1274
1272
1275
- if ( localFlags . Includes ( GeneralBitFlags . HeaderMasked ) )
1273
+ if ( localFlags . HasAny ( GeneralBitFlags . HeaderMasked ) )
1276
1274
{
1277
1275
if ( fileTime != 0 || fileDate != 0 )
1278
1276
{
1279
1277
throw new ZipException ( "Header masked set but date/time values non-zero" ) ;
1280
1278
}
1281
1279
}
1282
1280
1283
- if ( ! localFlags . Includes ( GeneralBitFlags . Descriptor ) )
1281
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Descriptor ) )
1284
1282
{
1285
1283
if ( crcValue != ( uint ) entry . Crc )
1286
1284
{
@@ -1350,7 +1348,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
1350
1348
1351
1349
// Size can be verified only if it is known in the local header.
1352
1350
// it will always be known in the central header.
1353
- if ( ! localFlags . Includes ( GeneralBitFlags . Descriptor ) ||
1351
+ if ( ! localFlags . HasAny ( GeneralBitFlags . Descriptor ) ||
1354
1352
( ( size > 0 || compressedSize > 0 ) && entry . Size > 0 ) )
1355
1353
{
1356
1354
if ( size != 0 && size != entry . Size )
@@ -2504,7 +2502,7 @@ private void CopyBytes(ZipUpdate update, Stream destination, Stream source,
2504
2502
/// <returns>The descriptor size, zero if there isn't one.</returns>
2505
2503
private static int GetDescriptorSize ( ZipUpdate update , bool includingSignature )
2506
2504
{
2507
- if ( ! ( ( GeneralBitFlags ) update . Entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) )
2505
+ if ( ! ( ( GeneralBitFlags ) update . Entry . Flags ) . HasAny ( GeneralBitFlags . Descriptor ) )
2508
2506
return 0 ;
2509
2507
2510
2508
var descriptorWithSignature = update . Entry . LocalHeaderRequiresZip64
0 commit comments