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