@zip.js/zip.js 2.8.58 → 2.8.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist/zip-core-external.js +157 -39
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +171 -38
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +157 -40
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +156 -39
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +157 -40
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +171 -39
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +171 -39
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +171 -38
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +171 -38
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +171 -38
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +171 -39
- package/index-native.min.js +1 -1
- package/index.cjs +171 -39
- package/index.d.cts +184 -1
- package/index.d.ts +184 -1
- package/index.min.js +1 -1
- package/lib/core/constants.js +2 -0
- package/lib/core/options.js +2 -0
- package/lib/core/zip-reader.js +143 -33
- package/lib/core/zip-writer.js +13 -6
- package/lib/zip-core-reader.js +16 -1
- package/package.json +1 -1
package/dist/zip-fs-core.js
CHANGED
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
const BITFLAG_LEVEL_FAST_MASK = 0b100;
|
|
83
83
|
const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
|
|
84
84
|
const BITFLAG_DATA_DESCRIPTOR = 0b1000;
|
|
85
|
+
const BITFLAG_COMPRESSED_PATCHED_DATA = 0b100000;
|
|
85
86
|
const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
|
|
86
87
|
const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
|
|
87
88
|
const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
|
|
@@ -199,6 +200,7 @@
|
|
|
199
200
|
const OPTION_USDZ = "usdz";
|
|
200
201
|
const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
|
|
201
202
|
const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
|
|
203
|
+
const OPTION_CENTRAL_EXTRA_FIELD = "centralExtraField";
|
|
202
204
|
const OPTION_STRICTNESS = "strictness";
|
|
203
205
|
const OPTION_FILENAME_VALIDATION = "filenameValidation";
|
|
204
206
|
const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
|
|
@@ -4126,6 +4128,21 @@
|
|
|
4126
4128
|
const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
|
|
4127
4129
|
const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
|
|
4128
4130
|
const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
|
|
4131
|
+
const WARNING_UNSORTED_CENTRAL_DIRECTORY = "unsorted central directory";
|
|
4132
|
+
const WARNING_UNKNOWN_VERSION = "unknown version needed to extract";
|
|
4133
|
+
const WARNING_COMPRESSED_PATCHED_DATA = "compressed patched data";
|
|
4134
|
+
const WARNING_MALFORMED_EXTRA_FIELD = "malformed extra field";
|
|
4135
|
+
const WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA = "unknown zip64 extensible data";
|
|
4136
|
+
const WARNING_WRAPPED_ENTRIES_COUNT = "wrapped entries count";
|
|
4137
|
+
const WARNING_APPENDED_DATA = "appended data";
|
|
4138
|
+
const WARNING_PREPENDED_DATA = "prepended data";
|
|
4139
|
+
const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA = "trailing central directory data";
|
|
4140
|
+
const WARNING_DUPLICATE_FILENAME = "duplicate filename";
|
|
4141
|
+
const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY = "mismatched zip64 end of central directory record";
|
|
4142
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG = "mismatched local file header (general purpose bit flag)";
|
|
4143
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD = "mismatched local file header (compression method)";
|
|
4144
|
+
const WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES = "mismatched local file header (crc32 or sizes)";
|
|
4145
|
+
const MAX_KNOWN_VERSION = 63;
|
|
4129
4146
|
const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
|
|
4130
4147
|
const CHARSET_UTF8 = "utf-8";
|
|
4131
4148
|
const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
|
|
@@ -4176,6 +4193,7 @@
|
|
|
4176
4193
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4177
4194
|
throw new Error(ERR_BAD_FORMAT);
|
|
4178
4195
|
}
|
|
4196
|
+
const warnings = zipReader.warnings = [];
|
|
4179
4197
|
const strictness = getStrictness(options, zipReader.options);
|
|
4180
4198
|
const checkAmbiguity = strictness == STRICTNESS_STRICT;
|
|
4181
4199
|
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
@@ -4199,8 +4217,12 @@
|
|
|
4199
4217
|
const commentOffset = endOfDirectoryInfo.offset;
|
|
4200
4218
|
const commentLength = getUint16$1(endOfDirectoryView, 20);
|
|
4201
4219
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
4202
|
-
|
|
4203
|
-
|
|
4220
|
+
const appendedDataLength = reader.size - appendedDataOffset;
|
|
4221
|
+
if (appendedDataLength > maxAppendedDataSize) {
|
|
4222
|
+
throwAmbiguousArchive(WARNING_APPENDED_DATA);
|
|
4223
|
+
}
|
|
4224
|
+
if (appendedDataLength > 0) {
|
|
4225
|
+
addWarning(warnings, WARNING_APPENDED_DATA);
|
|
4204
4226
|
}
|
|
4205
4227
|
let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
|
|
4206
4228
|
const expectedLastDiskNumber = reader.lastDiskNumber || 0;
|
|
@@ -4254,23 +4276,23 @@
|
|
|
4254
4276
|
}
|
|
4255
4277
|
if (lastDiskNumber == MAX_16_BITS) {
|
|
4256
4278
|
lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
|
|
4257
|
-
} else if (
|
|
4258
|
-
|
|
4279
|
+
} else if (lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
|
|
4280
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4259
4281
|
}
|
|
4260
4282
|
if (diskNumber == MAX_16_BITS) {
|
|
4261
4283
|
diskNumber = getUint32$1(endOfDirectoryView, 20);
|
|
4262
|
-
} else if (
|
|
4263
|
-
|
|
4284
|
+
} else if (diskNumber != getUint32$1(endOfDirectoryView, 20)) {
|
|
4285
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4264
4286
|
}
|
|
4265
4287
|
if (filesLength == MAX_16_BITS) {
|
|
4266
4288
|
filesLength = getBigUint64(endOfDirectoryView, 32);
|
|
4267
|
-
} else if (
|
|
4268
|
-
|
|
4289
|
+
} else if (filesLength != getBigUint64(endOfDirectoryView, 32)) {
|
|
4290
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4269
4291
|
}
|
|
4270
4292
|
if (directoryDataLength == MAX_32_BITS) {
|
|
4271
4293
|
directoryDataLength = getBigUint64(endOfDirectoryView, 40);
|
|
4272
|
-
} else if (
|
|
4273
|
-
|
|
4294
|
+
} else if (directoryDataLength != getBigUint64(endOfDirectoryView, 40)) {
|
|
4295
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY);
|
|
4274
4296
|
}
|
|
4275
4297
|
directoryDataOffset = getDiskOffset$1(reader, diskNumber) + getBigUint64(endOfDirectoryView, 48) + prependedDataLength;
|
|
4276
4298
|
}
|
|
@@ -4339,14 +4361,22 @@
|
|
|
4339
4361
|
declaredDirectoryDataLength = directoryArray.length;
|
|
4340
4362
|
decryptedDirectory = true;
|
|
4341
4363
|
}
|
|
4364
|
+
if (directoryEncryptionInfo && !decryptedDirectory &&
|
|
4365
|
+
(directoryArray.length < 4 || getUint32$1(directoryView, 0) == CENTRAL_FILE_HEADER_SIGNATURE)) {
|
|
4366
|
+
addWarning(warnings, WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA);
|
|
4367
|
+
}
|
|
4342
4368
|
startOffset = directoryDataOffset;
|
|
4343
4369
|
const filenameEncoding = getOptionValue$1(zipReader, options, OPTION_FILENAME_ENCODING);
|
|
4344
4370
|
const commentEncoding = getOptionValue$1(zipReader, options, OPTION_COMMENT_ENCODING);
|
|
4345
|
-
const filenames =
|
|
4371
|
+
const filenames = new Set();
|
|
4346
4372
|
let duplicateFilename;
|
|
4373
|
+
let previousEntryPosition = -1;
|
|
4347
4374
|
const recoverWrappedFilesLength = !checkAmbiguity && !zip64EndOfDirectory;
|
|
4348
4375
|
if (!filesLength && recoverWrappedFilesLength) {
|
|
4349
4376
|
filesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
4377
|
+
if (filesLength) {
|
|
4378
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
4379
|
+
}
|
|
4350
4380
|
}
|
|
4351
4381
|
for (let indexFile = 0; indexFile < filesLength; indexFile++) {
|
|
4352
4382
|
const fileEntry = new ZipEntry$1(reader, zipReader.options);
|
|
@@ -4425,15 +4455,26 @@
|
|
|
4425
4455
|
filename,
|
|
4426
4456
|
comment
|
|
4427
4457
|
});
|
|
4428
|
-
readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)
|
|
4458
|
+
if (readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6)) {
|
|
4459
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD, filename);
|
|
4460
|
+
}
|
|
4429
4461
|
fileEntry.offset += prependedDataLength;
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4462
|
+
const entryPosition = getDiskOffset$1(reader, fileEntry.diskNumberStart) + fileEntry.offset;
|
|
4463
|
+
startOffset = Math.min(entryPosition, startOffset);
|
|
4464
|
+
if (entryPosition < previousEntryPosition) {
|
|
4465
|
+
addWarning(warnings, WARNING_UNSORTED_CENTRAL_DIRECTORY, filename);
|
|
4466
|
+
}
|
|
4467
|
+
previousEntryPosition = entryPosition;
|
|
4468
|
+
if ((fileEntry.version & MAX_8_BITS) > MAX_KNOWN_VERSION) {
|
|
4469
|
+
addWarning(warnings, WARNING_UNKNOWN_VERSION, filename);
|
|
4470
|
+
}
|
|
4471
|
+
if ((fileEntry.rawBitFlag & BITFLAG_COMPRESSED_PATCHED_DATA) == BITFLAG_COMPRESSED_PATCHED_DATA) {
|
|
4472
|
+
addWarning(warnings, WARNING_COMPRESSED_PATCHED_DATA, filename);
|
|
4473
|
+
}
|
|
4474
|
+
if (filenames.has(fileEntry.filename)) {
|
|
4475
|
+
duplicateFilename = true;
|
|
4436
4476
|
}
|
|
4477
|
+
filenames.add(fileEntry.filename);
|
|
4437
4478
|
const unixExternalUpper = (fileEntry.externalFileAttributes >> 16) & MAX_16_BITS;
|
|
4438
4479
|
if (fileEntry.unixMode === UNDEFINED_VALUE && (unixExternalUpper & (FILE_ATTR_UNIX_DEFAULT_MASK | FILE_ATTR_UNIX_EXECUTABLE_MASK | FILE_ATTR_UNIX_TYPE_DIR)) != 0) {
|
|
4439
4480
|
fileEntry.unixMode = unixExternalUpper;
|
|
@@ -4471,7 +4512,11 @@
|
|
|
4471
4512
|
};
|
|
4472
4513
|
offset = endOffset;
|
|
4473
4514
|
if (indexFile == filesLength - 1 && recoverWrappedFilesLength) {
|
|
4474
|
-
|
|
4515
|
+
const wrappedFilesLength = getWrappedFilesLength(directoryView, directoryArray, offset);
|
|
4516
|
+
if (wrappedFilesLength) {
|
|
4517
|
+
filesLength += wrappedFilesLength;
|
|
4518
|
+
addWarning(warnings, WARNING_WRAPPED_ENTRIES_COUNT);
|
|
4519
|
+
}
|
|
4475
4520
|
}
|
|
4476
4521
|
const { onprogress } = options;
|
|
4477
4522
|
if (onprogress) {
|
|
@@ -4497,18 +4542,22 @@
|
|
|
4497
4542
|
zipReader.digitalSignature = digitalSignature;
|
|
4498
4543
|
offsetAfterSignature = offset + 6 + digitalSignature.length;
|
|
4499
4544
|
}
|
|
4500
|
-
if (
|
|
4501
|
-
|
|
4545
|
+
if ((offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) ||
|
|
4546
|
+
(!decryptedDirectory && offset != directoryDataLength && offsetAfterSignature != directoryDataLength)) {
|
|
4547
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_TRAILING_CENTRAL_DIRECTORY_DATA);
|
|
4502
4548
|
}
|
|
4503
4549
|
if (duplicateFilename) {
|
|
4504
|
-
|
|
4550
|
+
reportAmbiguity(checkAmbiguity, warnings, WARNING_DUPLICATE_FILENAME);
|
|
4505
4551
|
}
|
|
4506
4552
|
const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
|
|
4507
4553
|
const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
|
|
4508
4554
|
const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
|
|
4509
4555
|
startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
|
|
4510
4556
|
if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
|
|
4511
|
-
throwAmbiguousArchive(
|
|
4557
|
+
throwAmbiguousArchive(WARNING_PREPENDED_DATA);
|
|
4558
|
+
}
|
|
4559
|
+
if (prependedDataLength || (filesLength && startOffset > SPLIT_ZIP_FILE_SIGNATURE_LENGTH)) {
|
|
4560
|
+
addWarning(warnings, WARNING_PREPENDED_DATA);
|
|
4512
4561
|
}
|
|
4513
4562
|
if (extractPrependedData) {
|
|
4514
4563
|
zipReader.prependedData = startOffset > splitZipSignatureLength ?
|
|
@@ -4578,6 +4627,28 @@
|
|
|
4578
4627
|
}
|
|
4579
4628
|
}
|
|
4580
4629
|
|
|
4630
|
+
async function isZipFile(reader, options = {}) {
|
|
4631
|
+
reader = new GenericReader(reader);
|
|
4632
|
+
await initStream(reader);
|
|
4633
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
4634
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
4635
|
+
await initStream(reader);
|
|
4636
|
+
}
|
|
4637
|
+
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
4638
|
+
return false;
|
|
4639
|
+
}
|
|
4640
|
+
const strictness = getStrictness(options, {});
|
|
4641
|
+
const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
|
|
4642
|
+
const maxAppendedDataSize = getMaxAppendedDataSize(options[OPTION_MAX_APPENDED_DATA_SIZE], strictness);
|
|
4643
|
+
const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
|
|
4644
|
+
if (!endOfDirectoryInfo || (strictness == STRICTNESS_STRICT && endOfDirectoryReachingEndCount > 1)) {
|
|
4645
|
+
return false;
|
|
4646
|
+
}
|
|
4647
|
+
const commentLength = getUint16$1(getDataView(endOfDirectoryInfo), 20);
|
|
4648
|
+
const appendedDataOffset = endOfDirectoryInfo.offset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
4649
|
+
return reader.size - appendedDataOffset <= maxAppendedDataSize;
|
|
4650
|
+
}
|
|
4651
|
+
|
|
4581
4652
|
let ZipEntry$1 = class ZipEntry {
|
|
4582
4653
|
|
|
4583
4654
|
constructor(reader, options) {
|
|
@@ -4609,6 +4680,7 @@
|
|
|
4609
4680
|
dataDescriptor
|
|
4610
4681
|
} = bitFlag;
|
|
4611
4682
|
const localDirectory = fileEntry.localDirectory = {};
|
|
4683
|
+
const warnings = fileEntry.warnings = [];
|
|
4612
4684
|
const localHeaderOffset = getDiskOffset$1(reader, diskNumberStart) + offset;
|
|
4613
4685
|
const dataArray = await readUint8Array(reader, localHeaderOffset, HEADER_SIZE);
|
|
4614
4686
|
const dataView = getDataView(dataArray);
|
|
@@ -4649,10 +4721,10 @@
|
|
|
4649
4721
|
if (checkLocalFilename) {
|
|
4650
4722
|
localDirectory.rawFilename = rawLocalFilename;
|
|
4651
4723
|
}
|
|
4652
|
-
readCommonFooter(zipEntry, localDirectory, dataView, 4, true)
|
|
4653
|
-
|
|
4654
|
-
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
|
|
4724
|
+
if (readCommonFooter(zipEntry, localDirectory, dataView, 4, true)) {
|
|
4725
|
+
addWarning(warnings, WARNING_MALFORMED_EXTRA_FIELD);
|
|
4655
4726
|
}
|
|
4727
|
+
validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, checkLocalDirectory ? UNDEFINED_VALUE : warnings);
|
|
4656
4728
|
const { lastAccessDate, creationDate, uid, gid } = localDirectory;
|
|
4657
4729
|
if (lastAccessDate) {
|
|
4658
4730
|
fileEntry.lastAccessDate = lastAccessDate;
|
|
@@ -4878,6 +4950,7 @@
|
|
|
4878
4950
|
const extraField = directory.extraField = new Map();
|
|
4879
4951
|
const rawExtraFieldView = getDataView(rawExtraField);
|
|
4880
4952
|
let offsetExtraField = 0;
|
|
4953
|
+
let malformedExtraField = false;
|
|
4881
4954
|
try {
|
|
4882
4955
|
while (offsetExtraField < rawExtraField.length) {
|
|
4883
4956
|
const type = getUint16$1(rawExtraFieldView, offsetExtraField);
|
|
@@ -4889,7 +4962,10 @@
|
|
|
4889
4962
|
offsetExtraField += 4 + size;
|
|
4890
4963
|
}
|
|
4891
4964
|
} catch {
|
|
4892
|
-
|
|
4965
|
+
malformedExtraField = true;
|
|
4966
|
+
}
|
|
4967
|
+
if (offsetExtraField > rawExtraField.length) {
|
|
4968
|
+
malformedExtraField = true;
|
|
4893
4969
|
}
|
|
4894
4970
|
const compressionMethod = getUint16$1(dataView, offset + 4);
|
|
4895
4971
|
Object.assign(directory, {
|
|
@@ -4957,6 +5033,7 @@
|
|
|
4957
5033
|
if (extraFieldUSDZ) {
|
|
4958
5034
|
directory.extraFieldUSDZ = extraFieldUSDZ;
|
|
4959
5035
|
}
|
|
5036
|
+
return malformedExtraField;
|
|
4960
5037
|
}
|
|
4961
5038
|
|
|
4962
5039
|
function readExtraFieldZip64(extraFieldZip64, directory) {
|
|
@@ -5418,27 +5495,46 @@
|
|
|
5418
5495
|
return UNDEFINED_VALUE;
|
|
5419
5496
|
}
|
|
5420
5497
|
|
|
5421
|
-
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
|
|
5498
|
+
function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename, warnings) {
|
|
5422
5499
|
const { rawFilename } = zipEntry;
|
|
5500
|
+
const reject = !warnings;
|
|
5423
5501
|
const maskedLocalDirectory = zipEntry.decryptedDirectory &&
|
|
5424
5502
|
(localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
|
|
5425
5503
|
if (checkLocalFilename && !maskedLocalDirectory &&
|
|
5426
5504
|
(rawLocalFilename.length != rawFilename.length ||
|
|
5427
5505
|
rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
|
|
5428
|
-
|
|
5506
|
+
reportAmbiguity(reject, warnings, "mismatched local file header (filename)");
|
|
5429
5507
|
}
|
|
5430
5508
|
if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
|
|
5431
|
-
|
|
5509
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG);
|
|
5432
5510
|
}
|
|
5433
5511
|
if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
|
|
5434
|
-
|
|
5512
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD);
|
|
5435
5513
|
}
|
|
5436
5514
|
if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
|
|
5437
5515
|
(localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
|
|
5438
5516
|
(localDirectory.crc32 != zipEntry.crc32 ||
|
|
5439
5517
|
localDirectory.compressedSize != zipEntry.compressedSize ||
|
|
5440
5518
|
localDirectory.uncompressedSize != zipEntry.uncompressedSize)) {
|
|
5441
|
-
|
|
5519
|
+
reportAmbiguity(reject, warnings, WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES);
|
|
5520
|
+
}
|
|
5521
|
+
}
|
|
5522
|
+
|
|
5523
|
+
function reportAmbiguity(reject, warnings, reason) {
|
|
5524
|
+
if (reject) {
|
|
5525
|
+
throwAmbiguousArchive(reason);
|
|
5526
|
+
} else {
|
|
5527
|
+
addWarning(warnings, reason);
|
|
5528
|
+
}
|
|
5529
|
+
}
|
|
5530
|
+
|
|
5531
|
+
function addWarning(warnings, reason, filename) {
|
|
5532
|
+
if (!warnings.some(warning => warning.reason == reason)) {
|
|
5533
|
+
const warning = { reason };
|
|
5534
|
+
if (filename !== UNDEFINED_VALUE) {
|
|
5535
|
+
warning.filename = filename;
|
|
5536
|
+
}
|
|
5537
|
+
warnings.push(warning);
|
|
5442
5538
|
}
|
|
5443
5539
|
}
|
|
5444
5540
|
|
|
@@ -5515,8 +5611,23 @@
|
|
|
5515
5611
|
ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
|
|
5516
5612
|
ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
|
|
5517
5613
|
ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
|
|
5614
|
+
WARNING_APPENDED_DATA: WARNING_APPENDED_DATA,
|
|
5615
|
+
WARNING_COMPRESSED_PATCHED_DATA: WARNING_COMPRESSED_PATCHED_DATA,
|
|
5616
|
+
WARNING_DUPLICATE_FILENAME: WARNING_DUPLICATE_FILENAME,
|
|
5617
|
+
WARNING_MALFORMED_EXTRA_FIELD: WARNING_MALFORMED_EXTRA_FIELD,
|
|
5618
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG,
|
|
5619
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD,
|
|
5620
|
+
WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES,
|
|
5621
|
+
WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY,
|
|
5622
|
+
WARNING_PREPENDED_DATA: WARNING_PREPENDED_DATA,
|
|
5623
|
+
WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: WARNING_TRAILING_CENTRAL_DIRECTORY_DATA,
|
|
5624
|
+
WARNING_UNKNOWN_VERSION: WARNING_UNKNOWN_VERSION,
|
|
5625
|
+
WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA: WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA,
|
|
5626
|
+
WARNING_UNSORTED_CENTRAL_DIRECTORY: WARNING_UNSORTED_CENTRAL_DIRECTORY,
|
|
5627
|
+
WARNING_WRAPPED_ENTRIES_COUNT: WARNING_WRAPPED_ENTRIES_COUNT,
|
|
5518
5628
|
ZipReader: ZipReader,
|
|
5519
|
-
ZipReaderStream: ZipReaderStream
|
|
5629
|
+
ZipReaderStream: ZipReaderStream,
|
|
5630
|
+
isZipFile: isZipFile
|
|
5520
5631
|
});
|
|
5521
5632
|
|
|
5522
5633
|
/*
|
|
@@ -5729,6 +5840,7 @@
|
|
|
5729
5840
|
rawExtraFieldNTFS: EMPTY_UINT8_ARRAY,
|
|
5730
5841
|
rawExtraFieldUnix: EMPTY_UINT8_ARRAY,
|
|
5731
5842
|
rawExtraField,
|
|
5843
|
+
rawCentralExtraField: EMPTY_UINT8_ARRAY,
|
|
5732
5844
|
extendedTimestamp: false,
|
|
5733
5845
|
headerArray,
|
|
5734
5846
|
headerView
|
|
@@ -5838,7 +5950,6 @@
|
|
|
5838
5950
|
|
|
5839
5951
|
async function addFileEntry(zipWriter, name, reader, options) {
|
|
5840
5952
|
options = Object.assign({}, options);
|
|
5841
|
-
name = name.trim();
|
|
5842
5953
|
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
5843
5954
|
name += DIRECTORY_SIGNATURE;
|
|
5844
5955
|
}
|
|
@@ -5910,7 +6021,6 @@
|
|
|
5910
6021
|
}
|
|
5911
6022
|
|
|
5912
6023
|
function resolveAttributes(zipWriter, name, options) {
|
|
5913
|
-
name = name.trim();
|
|
5914
6024
|
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
5915
6025
|
let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
|
|
5916
6026
|
const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
|
|
@@ -6115,6 +6225,7 @@
|
|
|
6115
6225
|
}
|
|
6116
6226
|
const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
|
|
6117
6227
|
const rawLocalExtraField = serializeExtraField(options[OPTION_LOCAL_EXTRA_FIELD]);
|
|
6228
|
+
const rawCentralExtraField = serializeExtraField(options[OPTION_CENTRAL_EXTRA_FIELD]);
|
|
6118
6229
|
return {
|
|
6119
6230
|
comment,
|
|
6120
6231
|
resolvedOptions: {
|
|
@@ -6150,7 +6261,8 @@
|
|
|
6150
6261
|
dataDescriptor,
|
|
6151
6262
|
zip64,
|
|
6152
6263
|
rawExtraField,
|
|
6153
|
-
rawLocalExtraField
|
|
6264
|
+
rawLocalExtraField,
|
|
6265
|
+
rawCentralExtraField
|
|
6154
6266
|
}
|
|
6155
6267
|
};
|
|
6156
6268
|
}
|
|
@@ -6292,7 +6404,6 @@
|
|
|
6292
6404
|
let { name } = entry;
|
|
6293
6405
|
const { size } = entry;
|
|
6294
6406
|
const options = Object.assign({}, entry.options);
|
|
6295
|
-
name = name.trim();
|
|
6296
6407
|
if (getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY) && !name.endsWith(DIRECTORY_SIGNATURE)) {
|
|
6297
6408
|
name += DIRECTORY_SIGNATURE;
|
|
6298
6409
|
}
|
|
@@ -6548,6 +6659,7 @@
|
|
|
6548
6659
|
versionMadeBy,
|
|
6549
6660
|
rawComment,
|
|
6550
6661
|
rawExtraField,
|
|
6662
|
+
rawCentralExtraField,
|
|
6551
6663
|
useWebWorkers,
|
|
6552
6664
|
transferStreams,
|
|
6553
6665
|
onstart,
|
|
@@ -6591,6 +6703,7 @@
|
|
|
6591
6703
|
rawExtraFieldUnix,
|
|
6592
6704
|
rawExtraFieldAES,
|
|
6593
6705
|
rawExtraField,
|
|
6706
|
+
rawCentralExtraField,
|
|
6594
6707
|
extendedTimestamp,
|
|
6595
6708
|
msDosCompatible,
|
|
6596
6709
|
internalFileAttributes,
|
|
@@ -7091,6 +7204,7 @@
|
|
|
7091
7204
|
rawExtraFieldNTFS,
|
|
7092
7205
|
rawExtraFieldUnix,
|
|
7093
7206
|
rawExtraField,
|
|
7207
|
+
rawCentralExtraField,
|
|
7094
7208
|
extendedTimestamp,
|
|
7095
7209
|
extraFieldExtendedTimestampFlag,
|
|
7096
7210
|
lastModDate,
|
|
@@ -7145,7 +7259,8 @@
|
|
|
7145
7259
|
rawExtraFieldNTFS,
|
|
7146
7260
|
rawExtraFieldUnix,
|
|
7147
7261
|
rawExtraFieldTimestamp,
|
|
7148
|
-
rawExtraField
|
|
7262
|
+
rawExtraField,
|
|
7263
|
+
rawCentralExtraField);
|
|
7149
7264
|
if (extraFieldLength > MAX_16_BITS) {
|
|
7150
7265
|
throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
|
|
7151
7266
|
}
|
|
@@ -7173,6 +7288,7 @@
|
|
|
7173
7288
|
rawExtraFieldNTFS,
|
|
7174
7289
|
rawExtraFieldUnix,
|
|
7175
7290
|
rawExtraField,
|
|
7291
|
+
rawCentralExtraField,
|
|
7176
7292
|
rawComment,
|
|
7177
7293
|
versionMadeBy,
|
|
7178
7294
|
headerArray,
|
|
@@ -7187,7 +7303,7 @@
|
|
|
7187
7303
|
uncompressedSize,
|
|
7188
7304
|
compressedSize
|
|
7189
7305
|
} = fileEntry;
|
|
7190
|
-
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
|
|
7306
|
+
const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField, rawCentralExtraField);
|
|
7191
7307
|
const directoryRecordLength = CENTRAL_FILE_HEADER_LENGTH + getLength(rawFilename, rawComment) + extraFieldLength;
|
|
7192
7308
|
if (exceedsAvailableSize(writer, offset + directoryRecordLength - directoryDiskOffset)) {
|
|
7193
7309
|
await writeData(writer, directoryArray.slice(directoryDiskOffset, offset));
|
|
@@ -7225,6 +7341,7 @@
|
|
|
7225
7341
|
directoryRecord.writeBytes(rawExtraFieldNTFS);
|
|
7226
7342
|
directoryRecord.writeBytes(rawExtraFieldUnix);
|
|
7227
7343
|
directoryRecord.writeBytes(rawExtraField);
|
|
7344
|
+
directoryRecord.writeBytes(rawCentralExtraField);
|
|
7228
7345
|
directoryRecord.writeBytes(rawComment);
|
|
7229
7346
|
arraySet(directoryArray, directoryRecord.array, offset);
|
|
7230
7347
|
offset += directoryRecordLength;
|