@mdzip/editor-ng 2.4.0 → 2.4.2
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.
|
@@ -233,9 +233,9 @@ function binstring2buf(str) {
|
|
|
233
233
|
}
|
|
234
234
|
return buf;
|
|
235
235
|
}
|
|
236
|
-
function buf2string(buf,
|
|
236
|
+
function buf2string(buf, max2) {
|
|
237
237
|
var i, out, c, c_len;
|
|
238
|
-
var len =
|
|
238
|
+
var len = max2 || buf.length;
|
|
239
239
|
var utf16buf = new Array(len * 2);
|
|
240
240
|
for (out = 0, i = 0; i < len; ) {
|
|
241
241
|
c = buf[i++];
|
|
@@ -268,23 +268,23 @@ function buf2string(buf, max) {
|
|
|
268
268
|
}
|
|
269
269
|
return _buf2binstring(utf16buf, out);
|
|
270
270
|
}
|
|
271
|
-
function utf8border(buf,
|
|
271
|
+
function utf8border(buf, max2) {
|
|
272
272
|
var pos;
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
|
|
273
|
+
max2 = max2 || buf.length;
|
|
274
|
+
if (max2 > buf.length) {
|
|
275
|
+
max2 = buf.length;
|
|
276
276
|
}
|
|
277
|
-
pos =
|
|
277
|
+
pos = max2 - 1;
|
|
278
278
|
while (pos >= 0 && (buf[pos] & 192) === 128) {
|
|
279
279
|
pos--;
|
|
280
280
|
}
|
|
281
281
|
if (pos < 0) {
|
|
282
|
-
return
|
|
282
|
+
return max2;
|
|
283
283
|
}
|
|
284
284
|
if (pos === 0) {
|
|
285
|
-
return
|
|
285
|
+
return max2;
|
|
286
286
|
}
|
|
287
|
-
return pos + utf8len(buf[pos]) >
|
|
287
|
+
return pos + utf8len(buf[pos]) > max2 ? pos : max2;
|
|
288
288
|
}
|
|
289
289
|
function adler32(adler, buf, len, pos) {
|
|
290
290
|
var s1 = adler & 65535 | 0, s2 = adler >>> 16 & 65535 | 0, n = 0;
|
|
@@ -341,7 +341,7 @@ function inflate_fast(strm, start) {
|
|
|
341
341
|
var wnext;
|
|
342
342
|
var s_window;
|
|
343
343
|
var hold;
|
|
344
|
-
var
|
|
344
|
+
var bits2;
|
|
345
345
|
var lcode;
|
|
346
346
|
var dcode;
|
|
347
347
|
var lmask;
|
|
@@ -367,25 +367,25 @@ function inflate_fast(strm, start) {
|
|
|
367
367
|
wnext = state.wnext;
|
|
368
368
|
s_window = state.window;
|
|
369
369
|
hold = state.hold;
|
|
370
|
-
|
|
370
|
+
bits2 = state.bits;
|
|
371
371
|
lcode = state.lencode;
|
|
372
372
|
dcode = state.distcode;
|
|
373
373
|
lmask = (1 << state.lenbits) - 1;
|
|
374
374
|
dmask = (1 << state.distbits) - 1;
|
|
375
375
|
top:
|
|
376
376
|
do {
|
|
377
|
-
if (
|
|
378
|
-
hold += input[_in++] <<
|
|
379
|
-
|
|
380
|
-
hold += input[_in++] <<
|
|
381
|
-
|
|
377
|
+
if (bits2 < 15) {
|
|
378
|
+
hold += input[_in++] << bits2;
|
|
379
|
+
bits2 += 8;
|
|
380
|
+
hold += input[_in++] << bits2;
|
|
381
|
+
bits2 += 8;
|
|
382
382
|
}
|
|
383
383
|
here = lcode[hold & lmask];
|
|
384
384
|
dolen:
|
|
385
385
|
for (; ; ) {
|
|
386
386
|
op = here >>> 24;
|
|
387
387
|
hold >>>= op;
|
|
388
|
-
|
|
388
|
+
bits2 -= op;
|
|
389
389
|
op = here >>> 16 & 255;
|
|
390
390
|
if (op === 0) {
|
|
391
391
|
output[_out++] = here & 65535;
|
|
@@ -393,36 +393,36 @@ function inflate_fast(strm, start) {
|
|
|
393
393
|
len = here & 65535;
|
|
394
394
|
op &= 15;
|
|
395
395
|
if (op) {
|
|
396
|
-
if (
|
|
397
|
-
hold += input[_in++] <<
|
|
398
|
-
|
|
396
|
+
if (bits2 < op) {
|
|
397
|
+
hold += input[_in++] << bits2;
|
|
398
|
+
bits2 += 8;
|
|
399
399
|
}
|
|
400
400
|
len += hold & (1 << op) - 1;
|
|
401
401
|
hold >>>= op;
|
|
402
|
-
|
|
402
|
+
bits2 -= op;
|
|
403
403
|
}
|
|
404
|
-
if (
|
|
405
|
-
hold += input[_in++] <<
|
|
406
|
-
|
|
407
|
-
hold += input[_in++] <<
|
|
408
|
-
|
|
404
|
+
if (bits2 < 15) {
|
|
405
|
+
hold += input[_in++] << bits2;
|
|
406
|
+
bits2 += 8;
|
|
407
|
+
hold += input[_in++] << bits2;
|
|
408
|
+
bits2 += 8;
|
|
409
409
|
}
|
|
410
410
|
here = dcode[hold & dmask];
|
|
411
411
|
dodist:
|
|
412
412
|
for (; ; ) {
|
|
413
413
|
op = here >>> 24;
|
|
414
414
|
hold >>>= op;
|
|
415
|
-
|
|
415
|
+
bits2 -= op;
|
|
416
416
|
op = here >>> 16 & 255;
|
|
417
417
|
if (op & 16) {
|
|
418
418
|
dist = here & 65535;
|
|
419
419
|
op &= 15;
|
|
420
|
-
if (
|
|
421
|
-
hold += input[_in++] <<
|
|
422
|
-
|
|
423
|
-
if (
|
|
424
|
-
hold += input[_in++] <<
|
|
425
|
-
|
|
420
|
+
if (bits2 < op) {
|
|
421
|
+
hold += input[_in++] << bits2;
|
|
422
|
+
bits2 += 8;
|
|
423
|
+
if (bits2 < op) {
|
|
424
|
+
hold += input[_in++] << bits2;
|
|
425
|
+
bits2 += 8;
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
dist += hold & (1 << op) - 1;
|
|
@@ -432,7 +432,7 @@ function inflate_fast(strm, start) {
|
|
|
432
432
|
break top;
|
|
433
433
|
}
|
|
434
434
|
hold >>>= op;
|
|
435
|
-
|
|
435
|
+
bits2 -= op;
|
|
436
436
|
op = _out - beg;
|
|
437
437
|
if (dist > op) {
|
|
438
438
|
op = dist - op;
|
|
@@ -536,16 +536,16 @@ function inflate_fast(strm, start) {
|
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
538
538
|
} while (_in < last && _out < end2);
|
|
539
|
-
len =
|
|
539
|
+
len = bits2 >> 3;
|
|
540
540
|
_in -= len;
|
|
541
|
-
|
|
542
|
-
hold &= (1 <<
|
|
541
|
+
bits2 -= len << 3;
|
|
542
|
+
hold &= (1 << bits2) - 1;
|
|
543
543
|
strm.next_in = _in;
|
|
544
544
|
strm.next_out = _out;
|
|
545
545
|
strm.avail_in = _in < last ? 5 + (last - _in) : 5 - (_in - last);
|
|
546
546
|
strm.avail_out = _out < end2 ? 257 + (end2 - _out) : 257 - (_out - end2);
|
|
547
547
|
state.hold = hold;
|
|
548
|
-
state.bits =
|
|
548
|
+
state.bits = bits2;
|
|
549
549
|
return;
|
|
550
550
|
}
|
|
551
551
|
var MAXBITS = 15;
|
|
@@ -693,10 +693,10 @@ var dext = [
|
|
|
693
693
|
64
|
|
694
694
|
];
|
|
695
695
|
function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) {
|
|
696
|
-
var
|
|
696
|
+
var bits2 = opts.bits;
|
|
697
697
|
var len = 0;
|
|
698
698
|
var sym = 0;
|
|
699
|
-
var min = 0,
|
|
699
|
+
var min = 0, max2 = 0;
|
|
700
700
|
var root = 0;
|
|
701
701
|
var curr = 0;
|
|
702
702
|
var drop = 0;
|
|
@@ -722,22 +722,22 @@ function inflate_table(type, lens, lens_index, codes, table, table_index, work,
|
|
|
722
722
|
for (sym = 0; sym < codes; sym++) {
|
|
723
723
|
count[lens[lens_index + sym]]++;
|
|
724
724
|
}
|
|
725
|
-
root =
|
|
726
|
-
for (
|
|
727
|
-
if (count[
|
|
725
|
+
root = bits2;
|
|
726
|
+
for (max2 = MAXBITS; max2 >= 1; max2--) {
|
|
727
|
+
if (count[max2] !== 0) {
|
|
728
728
|
break;
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
|
-
if (root >
|
|
732
|
-
root =
|
|
731
|
+
if (root > max2) {
|
|
732
|
+
root = max2;
|
|
733
733
|
}
|
|
734
|
-
if (
|
|
734
|
+
if (max2 === 0) {
|
|
735
735
|
table[table_index++] = 1 << 24 | 64 << 16 | 0;
|
|
736
736
|
table[table_index++] = 1 << 24 | 64 << 16 | 0;
|
|
737
737
|
opts.bits = 1;
|
|
738
738
|
return 0;
|
|
739
739
|
}
|
|
740
|
-
for (min = 1; min <
|
|
740
|
+
for (min = 1; min < max2; min++) {
|
|
741
741
|
if (count[min] !== 0) {
|
|
742
742
|
break;
|
|
743
743
|
}
|
|
@@ -753,7 +753,7 @@ function inflate_table(type, lens, lens_index, codes, table, table_index, work,
|
|
|
753
753
|
return -1;
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
|
-
if (left > 0 && (type === CODES ||
|
|
756
|
+
if (left > 0 && (type === CODES || max2 !== 1)) {
|
|
757
757
|
return -1;
|
|
758
758
|
}
|
|
759
759
|
offs[1] = 0;
|
|
@@ -822,7 +822,7 @@ function inflate_table(type, lens, lens_index, codes, table, table_index, work,
|
|
|
822
822
|
}
|
|
823
823
|
sym++;
|
|
824
824
|
if (--count[len] === 0) {
|
|
825
|
-
if (len ===
|
|
825
|
+
if (len === max2) {
|
|
826
826
|
break;
|
|
827
827
|
}
|
|
828
828
|
len = lens[lens_index + work[sym]];
|
|
@@ -834,7 +834,7 @@ function inflate_table(type, lens, lens_index, codes, table, table_index, work,
|
|
|
834
834
|
next += min;
|
|
835
835
|
curr = len - drop;
|
|
836
836
|
left = 1 << curr;
|
|
837
|
-
while (curr + drop <
|
|
837
|
+
while (curr + drop < max2) {
|
|
838
838
|
left -= count[curr + drop];
|
|
839
839
|
if (left <= 0) {
|
|
840
840
|
break;
|
|
@@ -1097,7 +1097,7 @@ function inflate(strm, flush2) {
|
|
|
1097
1097
|
var put;
|
|
1098
1098
|
var have, left;
|
|
1099
1099
|
var hold;
|
|
1100
|
-
var
|
|
1100
|
+
var bits2;
|
|
1101
1101
|
var _in, _out;
|
|
1102
1102
|
var copy;
|
|
1103
1103
|
var from;
|
|
@@ -1128,7 +1128,7 @@ function inflate(strm, flush2) {
|
|
|
1128
1128
|
input = strm.input;
|
|
1129
1129
|
have = strm.avail_in;
|
|
1130
1130
|
hold = state.hold;
|
|
1131
|
-
|
|
1131
|
+
bits2 = state.bits;
|
|
1132
1132
|
_in = have;
|
|
1133
1133
|
_out = left;
|
|
1134
1134
|
ret = Z_OK$1;
|
|
@@ -1140,13 +1140,13 @@ function inflate(strm, flush2) {
|
|
|
1140
1140
|
state.mode = TYPEDO;
|
|
1141
1141
|
break;
|
|
1142
1142
|
}
|
|
1143
|
-
while (
|
|
1143
|
+
while (bits2 < 16) {
|
|
1144
1144
|
if (have === 0) {
|
|
1145
1145
|
break inf_leave;
|
|
1146
1146
|
}
|
|
1147
1147
|
have--;
|
|
1148
|
-
hold += input[next++] <<
|
|
1149
|
-
|
|
1148
|
+
hold += input[next++] << bits2;
|
|
1149
|
+
bits2 += 8;
|
|
1150
1150
|
}
|
|
1151
1151
|
if (state.wrap & 2 && hold === 35615) {
|
|
1152
1152
|
state.check = 0;
|
|
@@ -1154,7 +1154,7 @@ function inflate(strm, flush2) {
|
|
|
1154
1154
|
hbuf[1] = hold >>> 8 & 255;
|
|
1155
1155
|
state.check = crc32(state.check, hbuf, 2, 0);
|
|
1156
1156
|
hold = 0;
|
|
1157
|
-
|
|
1157
|
+
bits2 = 0;
|
|
1158
1158
|
state.mode = FLAGS;
|
|
1159
1159
|
break;
|
|
1160
1160
|
}
|
|
@@ -1174,7 +1174,7 @@ function inflate(strm, flush2) {
|
|
|
1174
1174
|
break;
|
|
1175
1175
|
}
|
|
1176
1176
|
hold >>>= 4;
|
|
1177
|
-
|
|
1177
|
+
bits2 -= 4;
|
|
1178
1178
|
len = (hold & 15) + 8;
|
|
1179
1179
|
if (state.wbits === 0) {
|
|
1180
1180
|
state.wbits = len;
|
|
@@ -1187,16 +1187,16 @@ function inflate(strm, flush2) {
|
|
|
1187
1187
|
strm.adler = state.check = 1;
|
|
1188
1188
|
state.mode = hold & 512 ? DICTID : TYPE$1;
|
|
1189
1189
|
hold = 0;
|
|
1190
|
-
|
|
1190
|
+
bits2 = 0;
|
|
1191
1191
|
break;
|
|
1192
1192
|
case FLAGS:
|
|
1193
|
-
while (
|
|
1193
|
+
while (bits2 < 16) {
|
|
1194
1194
|
if (have === 0) {
|
|
1195
1195
|
break inf_leave;
|
|
1196
1196
|
}
|
|
1197
1197
|
have--;
|
|
1198
|
-
hold += input[next++] <<
|
|
1199
|
-
|
|
1198
|
+
hold += input[next++] << bits2;
|
|
1199
|
+
bits2 += 8;
|
|
1200
1200
|
}
|
|
1201
1201
|
state.flags = hold;
|
|
1202
1202
|
if ((state.flags & 255) !== Z_DEFLATED$1) {
|
|
@@ -1218,17 +1218,17 @@ function inflate(strm, flush2) {
|
|
|
1218
1218
|
state.check = crc32(state.check, hbuf, 2, 0);
|
|
1219
1219
|
}
|
|
1220
1220
|
hold = 0;
|
|
1221
|
-
|
|
1221
|
+
bits2 = 0;
|
|
1222
1222
|
state.mode = TIME;
|
|
1223
1223
|
/* falls through */
|
|
1224
1224
|
case TIME:
|
|
1225
|
-
while (
|
|
1225
|
+
while (bits2 < 32) {
|
|
1226
1226
|
if (have === 0) {
|
|
1227
1227
|
break inf_leave;
|
|
1228
1228
|
}
|
|
1229
1229
|
have--;
|
|
1230
|
-
hold += input[next++] <<
|
|
1231
|
-
|
|
1230
|
+
hold += input[next++] << bits2;
|
|
1231
|
+
bits2 += 8;
|
|
1232
1232
|
}
|
|
1233
1233
|
if (state.head) {
|
|
1234
1234
|
state.head.time = hold;
|
|
@@ -1241,17 +1241,17 @@ function inflate(strm, flush2) {
|
|
|
1241
1241
|
state.check = crc32(state.check, hbuf, 4, 0);
|
|
1242
1242
|
}
|
|
1243
1243
|
hold = 0;
|
|
1244
|
-
|
|
1244
|
+
bits2 = 0;
|
|
1245
1245
|
state.mode = OS;
|
|
1246
1246
|
/* falls through */
|
|
1247
1247
|
case OS:
|
|
1248
|
-
while (
|
|
1248
|
+
while (bits2 < 16) {
|
|
1249
1249
|
if (have === 0) {
|
|
1250
1250
|
break inf_leave;
|
|
1251
1251
|
}
|
|
1252
1252
|
have--;
|
|
1253
|
-
hold += input[next++] <<
|
|
1254
|
-
|
|
1253
|
+
hold += input[next++] << bits2;
|
|
1254
|
+
bits2 += 8;
|
|
1255
1255
|
}
|
|
1256
1256
|
if (state.head) {
|
|
1257
1257
|
state.head.xflags = hold & 255;
|
|
@@ -1263,18 +1263,18 @@ function inflate(strm, flush2) {
|
|
|
1263
1263
|
state.check = crc32(state.check, hbuf, 2, 0);
|
|
1264
1264
|
}
|
|
1265
1265
|
hold = 0;
|
|
1266
|
-
|
|
1266
|
+
bits2 = 0;
|
|
1267
1267
|
state.mode = EXLEN;
|
|
1268
1268
|
/* falls through */
|
|
1269
1269
|
case EXLEN:
|
|
1270
1270
|
if (state.flags & 1024) {
|
|
1271
|
-
while (
|
|
1271
|
+
while (bits2 < 16) {
|
|
1272
1272
|
if (have === 0) {
|
|
1273
1273
|
break inf_leave;
|
|
1274
1274
|
}
|
|
1275
1275
|
have--;
|
|
1276
|
-
hold += input[next++] <<
|
|
1277
|
-
|
|
1276
|
+
hold += input[next++] << bits2;
|
|
1277
|
+
bits2 += 8;
|
|
1278
1278
|
}
|
|
1279
1279
|
state.length = hold;
|
|
1280
1280
|
if (state.head) {
|
|
@@ -1286,7 +1286,7 @@ function inflate(strm, flush2) {
|
|
|
1286
1286
|
state.check = crc32(state.check, hbuf, 2, 0);
|
|
1287
1287
|
}
|
|
1288
1288
|
hold = 0;
|
|
1289
|
-
|
|
1289
|
+
bits2 = 0;
|
|
1290
1290
|
} else if (state.head) {
|
|
1291
1291
|
state.head.extra = null;
|
|
1292
1292
|
}
|
|
@@ -1382,13 +1382,13 @@ function inflate(strm, flush2) {
|
|
|
1382
1382
|
/* falls through */
|
|
1383
1383
|
case HCRC:
|
|
1384
1384
|
if (state.flags & 512) {
|
|
1385
|
-
while (
|
|
1385
|
+
while (bits2 < 16) {
|
|
1386
1386
|
if (have === 0) {
|
|
1387
1387
|
break inf_leave;
|
|
1388
1388
|
}
|
|
1389
1389
|
have--;
|
|
1390
|
-
hold += input[next++] <<
|
|
1391
|
-
|
|
1390
|
+
hold += input[next++] << bits2;
|
|
1391
|
+
bits2 += 8;
|
|
1392
1392
|
}
|
|
1393
1393
|
if (hold !== (state.check & 65535)) {
|
|
1394
1394
|
strm.msg = "header crc mismatch";
|
|
@@ -1396,7 +1396,7 @@ function inflate(strm, flush2) {
|
|
|
1396
1396
|
break;
|
|
1397
1397
|
}
|
|
1398
1398
|
hold = 0;
|
|
1399
|
-
|
|
1399
|
+
bits2 = 0;
|
|
1400
1400
|
}
|
|
1401
1401
|
if (state.head) {
|
|
1402
1402
|
state.head.hcrc = state.flags >> 9 & 1;
|
|
@@ -1406,17 +1406,17 @@ function inflate(strm, flush2) {
|
|
|
1406
1406
|
state.mode = TYPE$1;
|
|
1407
1407
|
break;
|
|
1408
1408
|
case DICTID:
|
|
1409
|
-
while (
|
|
1409
|
+
while (bits2 < 32) {
|
|
1410
1410
|
if (have === 0) {
|
|
1411
1411
|
break inf_leave;
|
|
1412
1412
|
}
|
|
1413
1413
|
have--;
|
|
1414
|
-
hold += input[next++] <<
|
|
1415
|
-
|
|
1414
|
+
hold += input[next++] << bits2;
|
|
1415
|
+
bits2 += 8;
|
|
1416
1416
|
}
|
|
1417
1417
|
strm.adler = state.check = zswap32(hold);
|
|
1418
1418
|
hold = 0;
|
|
1419
|
-
|
|
1419
|
+
bits2 = 0;
|
|
1420
1420
|
state.mode = DICT;
|
|
1421
1421
|
/* falls through */
|
|
1422
1422
|
case DICT:
|
|
@@ -1426,7 +1426,7 @@ function inflate(strm, flush2) {
|
|
|
1426
1426
|
strm.next_in = next;
|
|
1427
1427
|
strm.avail_in = have;
|
|
1428
1428
|
state.hold = hold;
|
|
1429
|
-
state.bits =
|
|
1429
|
+
state.bits = bits2;
|
|
1430
1430
|
return Z_NEED_DICT$1;
|
|
1431
1431
|
}
|
|
1432
1432
|
strm.adler = state.check = 1;
|
|
@@ -1439,22 +1439,22 @@ function inflate(strm, flush2) {
|
|
|
1439
1439
|
/* falls through */
|
|
1440
1440
|
case TYPEDO:
|
|
1441
1441
|
if (state.last) {
|
|
1442
|
-
hold >>>=
|
|
1443
|
-
|
|
1442
|
+
hold >>>= bits2 & 7;
|
|
1443
|
+
bits2 -= bits2 & 7;
|
|
1444
1444
|
state.mode = CHECK;
|
|
1445
1445
|
break;
|
|
1446
1446
|
}
|
|
1447
|
-
while (
|
|
1447
|
+
while (bits2 < 3) {
|
|
1448
1448
|
if (have === 0) {
|
|
1449
1449
|
break inf_leave;
|
|
1450
1450
|
}
|
|
1451
1451
|
have--;
|
|
1452
|
-
hold += input[next++] <<
|
|
1453
|
-
|
|
1452
|
+
hold += input[next++] << bits2;
|
|
1453
|
+
bits2 += 8;
|
|
1454
1454
|
}
|
|
1455
1455
|
state.last = hold & 1;
|
|
1456
1456
|
hold >>>= 1;
|
|
1457
|
-
|
|
1457
|
+
bits2 -= 1;
|
|
1458
1458
|
switch (hold & 3) {
|
|
1459
1459
|
case 0:
|
|
1460
1460
|
state.mode = STORED;
|
|
@@ -1464,7 +1464,7 @@ function inflate(strm, flush2) {
|
|
|
1464
1464
|
state.mode = LEN_;
|
|
1465
1465
|
if (flush2 === Z_TREES$1) {
|
|
1466
1466
|
hold >>>= 2;
|
|
1467
|
-
|
|
1467
|
+
bits2 -= 2;
|
|
1468
1468
|
break inf_leave;
|
|
1469
1469
|
}
|
|
1470
1470
|
break;
|
|
@@ -1476,18 +1476,18 @@ function inflate(strm, flush2) {
|
|
|
1476
1476
|
state.mode = BAD$1;
|
|
1477
1477
|
}
|
|
1478
1478
|
hold >>>= 2;
|
|
1479
|
-
|
|
1479
|
+
bits2 -= 2;
|
|
1480
1480
|
break;
|
|
1481
1481
|
case STORED:
|
|
1482
|
-
hold >>>=
|
|
1483
|
-
|
|
1484
|
-
while (
|
|
1482
|
+
hold >>>= bits2 & 7;
|
|
1483
|
+
bits2 -= bits2 & 7;
|
|
1484
|
+
while (bits2 < 32) {
|
|
1485
1485
|
if (have === 0) {
|
|
1486
1486
|
break inf_leave;
|
|
1487
1487
|
}
|
|
1488
1488
|
have--;
|
|
1489
|
-
hold += input[next++] <<
|
|
1490
|
-
|
|
1489
|
+
hold += input[next++] << bits2;
|
|
1490
|
+
bits2 += 8;
|
|
1491
1491
|
}
|
|
1492
1492
|
if ((hold & 65535) !== (hold >>> 16 ^ 65535)) {
|
|
1493
1493
|
strm.msg = "invalid stored block lengths";
|
|
@@ -1496,7 +1496,7 @@ function inflate(strm, flush2) {
|
|
|
1496
1496
|
}
|
|
1497
1497
|
state.length = hold & 65535;
|
|
1498
1498
|
hold = 0;
|
|
1499
|
-
|
|
1499
|
+
bits2 = 0;
|
|
1500
1500
|
state.mode = COPY_;
|
|
1501
1501
|
if (flush2 === Z_TREES$1) {
|
|
1502
1502
|
break inf_leave;
|
|
@@ -1528,23 +1528,23 @@ function inflate(strm, flush2) {
|
|
|
1528
1528
|
state.mode = TYPE$1;
|
|
1529
1529
|
break;
|
|
1530
1530
|
case TABLE:
|
|
1531
|
-
while (
|
|
1531
|
+
while (bits2 < 14) {
|
|
1532
1532
|
if (have === 0) {
|
|
1533
1533
|
break inf_leave;
|
|
1534
1534
|
}
|
|
1535
1535
|
have--;
|
|
1536
|
-
hold += input[next++] <<
|
|
1537
|
-
|
|
1536
|
+
hold += input[next++] << bits2;
|
|
1537
|
+
bits2 += 8;
|
|
1538
1538
|
}
|
|
1539
1539
|
state.nlen = (hold & 31) + 257;
|
|
1540
1540
|
hold >>>= 5;
|
|
1541
|
-
|
|
1541
|
+
bits2 -= 5;
|
|
1542
1542
|
state.ndist = (hold & 31) + 1;
|
|
1543
1543
|
hold >>>= 5;
|
|
1544
|
-
|
|
1544
|
+
bits2 -= 5;
|
|
1545
1545
|
state.ncode = (hold & 15) + 4;
|
|
1546
1546
|
hold >>>= 4;
|
|
1547
|
-
|
|
1547
|
+
bits2 -= 4;
|
|
1548
1548
|
if (state.nlen > 286 || state.ndist > 30) {
|
|
1549
1549
|
strm.msg = "too many length or distance symbols";
|
|
1550
1550
|
state.mode = BAD$1;
|
|
@@ -1555,17 +1555,17 @@ function inflate(strm, flush2) {
|
|
|
1555
1555
|
/* falls through */
|
|
1556
1556
|
case LENLENS:
|
|
1557
1557
|
while (state.have < state.ncode) {
|
|
1558
|
-
while (
|
|
1558
|
+
while (bits2 < 3) {
|
|
1559
1559
|
if (have === 0) {
|
|
1560
1560
|
break inf_leave;
|
|
1561
1561
|
}
|
|
1562
1562
|
have--;
|
|
1563
|
-
hold += input[next++] <<
|
|
1564
|
-
|
|
1563
|
+
hold += input[next++] << bits2;
|
|
1564
|
+
bits2 += 8;
|
|
1565
1565
|
}
|
|
1566
1566
|
state.lens[order[state.have++]] = hold & 7;
|
|
1567
1567
|
hold >>>= 3;
|
|
1568
|
-
|
|
1568
|
+
bits2 -= 3;
|
|
1569
1569
|
}
|
|
1570
1570
|
while (state.have < 19) {
|
|
1571
1571
|
state.lens[order[state.have++]] = 0;
|
|
@@ -1590,33 +1590,33 @@ function inflate(strm, flush2) {
|
|
|
1590
1590
|
here_bits = here >>> 24;
|
|
1591
1591
|
here_op = here >>> 16 & 255;
|
|
1592
1592
|
here_val = here & 65535;
|
|
1593
|
-
if (here_bits <=
|
|
1593
|
+
if (here_bits <= bits2) {
|
|
1594
1594
|
break;
|
|
1595
1595
|
}
|
|
1596
1596
|
if (have === 0) {
|
|
1597
1597
|
break inf_leave;
|
|
1598
1598
|
}
|
|
1599
1599
|
have--;
|
|
1600
|
-
hold += input[next++] <<
|
|
1601
|
-
|
|
1600
|
+
hold += input[next++] << bits2;
|
|
1601
|
+
bits2 += 8;
|
|
1602
1602
|
}
|
|
1603
1603
|
if (here_val < 16) {
|
|
1604
1604
|
hold >>>= here_bits;
|
|
1605
|
-
|
|
1605
|
+
bits2 -= here_bits;
|
|
1606
1606
|
state.lens[state.have++] = here_val;
|
|
1607
1607
|
} else {
|
|
1608
1608
|
if (here_val === 16) {
|
|
1609
1609
|
n = here_bits + 2;
|
|
1610
|
-
while (
|
|
1610
|
+
while (bits2 < n) {
|
|
1611
1611
|
if (have === 0) {
|
|
1612
1612
|
break inf_leave;
|
|
1613
1613
|
}
|
|
1614
1614
|
have--;
|
|
1615
|
-
hold += input[next++] <<
|
|
1616
|
-
|
|
1615
|
+
hold += input[next++] << bits2;
|
|
1616
|
+
bits2 += 8;
|
|
1617
1617
|
}
|
|
1618
1618
|
hold >>>= here_bits;
|
|
1619
|
-
|
|
1619
|
+
bits2 -= here_bits;
|
|
1620
1620
|
if (state.have === 0) {
|
|
1621
1621
|
strm.msg = "invalid bit length repeat";
|
|
1622
1622
|
state.mode = BAD$1;
|
|
@@ -1625,39 +1625,39 @@ function inflate(strm, flush2) {
|
|
|
1625
1625
|
len = state.lens[state.have - 1];
|
|
1626
1626
|
copy = 3 + (hold & 3);
|
|
1627
1627
|
hold >>>= 2;
|
|
1628
|
-
|
|
1628
|
+
bits2 -= 2;
|
|
1629
1629
|
} else if (here_val === 17) {
|
|
1630
1630
|
n = here_bits + 3;
|
|
1631
|
-
while (
|
|
1631
|
+
while (bits2 < n) {
|
|
1632
1632
|
if (have === 0) {
|
|
1633
1633
|
break inf_leave;
|
|
1634
1634
|
}
|
|
1635
1635
|
have--;
|
|
1636
|
-
hold += input[next++] <<
|
|
1637
|
-
|
|
1636
|
+
hold += input[next++] << bits2;
|
|
1637
|
+
bits2 += 8;
|
|
1638
1638
|
}
|
|
1639
1639
|
hold >>>= here_bits;
|
|
1640
|
-
|
|
1640
|
+
bits2 -= here_bits;
|
|
1641
1641
|
len = 0;
|
|
1642
1642
|
copy = 3 + (hold & 7);
|
|
1643
1643
|
hold >>>= 3;
|
|
1644
|
-
|
|
1644
|
+
bits2 -= 3;
|
|
1645
1645
|
} else {
|
|
1646
1646
|
n = here_bits + 7;
|
|
1647
|
-
while (
|
|
1647
|
+
while (bits2 < n) {
|
|
1648
1648
|
if (have === 0) {
|
|
1649
1649
|
break inf_leave;
|
|
1650
1650
|
}
|
|
1651
1651
|
have--;
|
|
1652
|
-
hold += input[next++] <<
|
|
1653
|
-
|
|
1652
|
+
hold += input[next++] << bits2;
|
|
1653
|
+
bits2 += 8;
|
|
1654
1654
|
}
|
|
1655
1655
|
hold >>>= here_bits;
|
|
1656
|
-
|
|
1656
|
+
bits2 -= here_bits;
|
|
1657
1657
|
len = 0;
|
|
1658
1658
|
copy = 11 + (hold & 127);
|
|
1659
1659
|
hold >>>= 7;
|
|
1660
|
-
|
|
1660
|
+
bits2 -= 7;
|
|
1661
1661
|
}
|
|
1662
1662
|
if (state.have + copy > state.nlen + state.ndist) {
|
|
1663
1663
|
strm.msg = "invalid bit length repeat";
|
|
@@ -1711,7 +1711,7 @@ function inflate(strm, flush2) {
|
|
|
1711
1711
|
strm.next_in = next;
|
|
1712
1712
|
strm.avail_in = have;
|
|
1713
1713
|
state.hold = hold;
|
|
1714
|
-
state.bits =
|
|
1714
|
+
state.bits = bits2;
|
|
1715
1715
|
inflate_fast(strm, _out);
|
|
1716
1716
|
put = strm.next_out;
|
|
1717
1717
|
output = strm.output;
|
|
@@ -1720,7 +1720,7 @@ function inflate(strm, flush2) {
|
|
|
1720
1720
|
input = strm.input;
|
|
1721
1721
|
have = strm.avail_in;
|
|
1722
1722
|
hold = state.hold;
|
|
1723
|
-
|
|
1723
|
+
bits2 = state.bits;
|
|
1724
1724
|
if (state.mode === TYPE$1) {
|
|
1725
1725
|
state.back = -1;
|
|
1726
1726
|
}
|
|
@@ -1732,15 +1732,15 @@ function inflate(strm, flush2) {
|
|
|
1732
1732
|
here_bits = here >>> 24;
|
|
1733
1733
|
here_op = here >>> 16 & 255;
|
|
1734
1734
|
here_val = here & 65535;
|
|
1735
|
-
if (here_bits <=
|
|
1735
|
+
if (here_bits <= bits2) {
|
|
1736
1736
|
break;
|
|
1737
1737
|
}
|
|
1738
1738
|
if (have === 0) {
|
|
1739
1739
|
break inf_leave;
|
|
1740
1740
|
}
|
|
1741
1741
|
have--;
|
|
1742
|
-
hold += input[next++] <<
|
|
1743
|
-
|
|
1742
|
+
hold += input[next++] << bits2;
|
|
1743
|
+
bits2 += 8;
|
|
1744
1744
|
}
|
|
1745
1745
|
if (here_op && (here_op & 240) === 0) {
|
|
1746
1746
|
last_bits = here_bits;
|
|
@@ -1751,22 +1751,22 @@ function inflate(strm, flush2) {
|
|
|
1751
1751
|
here_bits = here >>> 24;
|
|
1752
1752
|
here_op = here >>> 16 & 255;
|
|
1753
1753
|
here_val = here & 65535;
|
|
1754
|
-
if (last_bits + here_bits <=
|
|
1754
|
+
if (last_bits + here_bits <= bits2) {
|
|
1755
1755
|
break;
|
|
1756
1756
|
}
|
|
1757
1757
|
if (have === 0) {
|
|
1758
1758
|
break inf_leave;
|
|
1759
1759
|
}
|
|
1760
1760
|
have--;
|
|
1761
|
-
hold += input[next++] <<
|
|
1762
|
-
|
|
1761
|
+
hold += input[next++] << bits2;
|
|
1762
|
+
bits2 += 8;
|
|
1763
1763
|
}
|
|
1764
1764
|
hold >>>= last_bits;
|
|
1765
|
-
|
|
1765
|
+
bits2 -= last_bits;
|
|
1766
1766
|
state.back += last_bits;
|
|
1767
1767
|
}
|
|
1768
1768
|
hold >>>= here_bits;
|
|
1769
|
-
|
|
1769
|
+
bits2 -= here_bits;
|
|
1770
1770
|
state.back += here_bits;
|
|
1771
1771
|
state.length = here_val;
|
|
1772
1772
|
if (here_op === 0) {
|
|
@@ -1789,17 +1789,17 @@ function inflate(strm, flush2) {
|
|
|
1789
1789
|
case LENEXT:
|
|
1790
1790
|
if (state.extra) {
|
|
1791
1791
|
n = state.extra;
|
|
1792
|
-
while (
|
|
1792
|
+
while (bits2 < n) {
|
|
1793
1793
|
if (have === 0) {
|
|
1794
1794
|
break inf_leave;
|
|
1795
1795
|
}
|
|
1796
1796
|
have--;
|
|
1797
|
-
hold += input[next++] <<
|
|
1798
|
-
|
|
1797
|
+
hold += input[next++] << bits2;
|
|
1798
|
+
bits2 += 8;
|
|
1799
1799
|
}
|
|
1800
1800
|
state.length += hold & (1 << state.extra) - 1;
|
|
1801
1801
|
hold >>>= state.extra;
|
|
1802
|
-
|
|
1802
|
+
bits2 -= state.extra;
|
|
1803
1803
|
state.back += state.extra;
|
|
1804
1804
|
}
|
|
1805
1805
|
state.was = state.length;
|
|
@@ -1811,15 +1811,15 @@ function inflate(strm, flush2) {
|
|
|
1811
1811
|
here_bits = here >>> 24;
|
|
1812
1812
|
here_op = here >>> 16 & 255;
|
|
1813
1813
|
here_val = here & 65535;
|
|
1814
|
-
if (here_bits <=
|
|
1814
|
+
if (here_bits <= bits2) {
|
|
1815
1815
|
break;
|
|
1816
1816
|
}
|
|
1817
1817
|
if (have === 0) {
|
|
1818
1818
|
break inf_leave;
|
|
1819
1819
|
}
|
|
1820
1820
|
have--;
|
|
1821
|
-
hold += input[next++] <<
|
|
1822
|
-
|
|
1821
|
+
hold += input[next++] << bits2;
|
|
1822
|
+
bits2 += 8;
|
|
1823
1823
|
}
|
|
1824
1824
|
if ((here_op & 240) === 0) {
|
|
1825
1825
|
last_bits = here_bits;
|
|
@@ -1830,22 +1830,22 @@ function inflate(strm, flush2) {
|
|
|
1830
1830
|
here_bits = here >>> 24;
|
|
1831
1831
|
here_op = here >>> 16 & 255;
|
|
1832
1832
|
here_val = here & 65535;
|
|
1833
|
-
if (last_bits + here_bits <=
|
|
1833
|
+
if (last_bits + here_bits <= bits2) {
|
|
1834
1834
|
break;
|
|
1835
1835
|
}
|
|
1836
1836
|
if (have === 0) {
|
|
1837
1837
|
break inf_leave;
|
|
1838
1838
|
}
|
|
1839
1839
|
have--;
|
|
1840
|
-
hold += input[next++] <<
|
|
1841
|
-
|
|
1840
|
+
hold += input[next++] << bits2;
|
|
1841
|
+
bits2 += 8;
|
|
1842
1842
|
}
|
|
1843
1843
|
hold >>>= last_bits;
|
|
1844
|
-
|
|
1844
|
+
bits2 -= last_bits;
|
|
1845
1845
|
state.back += last_bits;
|
|
1846
1846
|
}
|
|
1847
1847
|
hold >>>= here_bits;
|
|
1848
|
-
|
|
1848
|
+
bits2 -= here_bits;
|
|
1849
1849
|
state.back += here_bits;
|
|
1850
1850
|
if (here_op & 64) {
|
|
1851
1851
|
strm.msg = "invalid distance code";
|
|
@@ -1859,17 +1859,17 @@ function inflate(strm, flush2) {
|
|
|
1859
1859
|
case DISTEXT:
|
|
1860
1860
|
if (state.extra) {
|
|
1861
1861
|
n = state.extra;
|
|
1862
|
-
while (
|
|
1862
|
+
while (bits2 < n) {
|
|
1863
1863
|
if (have === 0) {
|
|
1864
1864
|
break inf_leave;
|
|
1865
1865
|
}
|
|
1866
1866
|
have--;
|
|
1867
|
-
hold += input[next++] <<
|
|
1868
|
-
|
|
1867
|
+
hold += input[next++] << bits2;
|
|
1868
|
+
bits2 += 8;
|
|
1869
1869
|
}
|
|
1870
1870
|
state.offset += hold & (1 << state.extra) - 1;
|
|
1871
1871
|
hold >>>= state.extra;
|
|
1872
|
-
|
|
1872
|
+
bits2 -= state.extra;
|
|
1873
1873
|
state.back += state.extra;
|
|
1874
1874
|
}
|
|
1875
1875
|
if (state.offset > state.dmax) {
|
|
@@ -1930,13 +1930,13 @@ function inflate(strm, flush2) {
|
|
|
1930
1930
|
break;
|
|
1931
1931
|
case CHECK:
|
|
1932
1932
|
if (state.wrap) {
|
|
1933
|
-
while (
|
|
1933
|
+
while (bits2 < 32) {
|
|
1934
1934
|
if (have === 0) {
|
|
1935
1935
|
break inf_leave;
|
|
1936
1936
|
}
|
|
1937
1937
|
have--;
|
|
1938
|
-
hold |= input[next++] <<
|
|
1939
|
-
|
|
1938
|
+
hold |= input[next++] << bits2;
|
|
1939
|
+
bits2 += 8;
|
|
1940
1940
|
}
|
|
1941
1941
|
_out -= left;
|
|
1942
1942
|
strm.total_out += _out;
|
|
@@ -1952,19 +1952,19 @@ function inflate(strm, flush2) {
|
|
|
1952
1952
|
break;
|
|
1953
1953
|
}
|
|
1954
1954
|
hold = 0;
|
|
1955
|
-
|
|
1955
|
+
bits2 = 0;
|
|
1956
1956
|
}
|
|
1957
1957
|
state.mode = LENGTH;
|
|
1958
1958
|
/* falls through */
|
|
1959
1959
|
case LENGTH:
|
|
1960
1960
|
if (state.wrap && state.flags) {
|
|
1961
|
-
while (
|
|
1961
|
+
while (bits2 < 32) {
|
|
1962
1962
|
if (have === 0) {
|
|
1963
1963
|
break inf_leave;
|
|
1964
1964
|
}
|
|
1965
1965
|
have--;
|
|
1966
|
-
hold += input[next++] <<
|
|
1967
|
-
|
|
1966
|
+
hold += input[next++] << bits2;
|
|
1967
|
+
bits2 += 8;
|
|
1968
1968
|
}
|
|
1969
1969
|
if (hold !== (state.total & 4294967295)) {
|
|
1970
1970
|
strm.msg = "incorrect length check";
|
|
@@ -1972,7 +1972,7 @@ function inflate(strm, flush2) {
|
|
|
1972
1972
|
break;
|
|
1973
1973
|
}
|
|
1974
1974
|
hold = 0;
|
|
1975
|
-
|
|
1975
|
+
bits2 = 0;
|
|
1976
1976
|
}
|
|
1977
1977
|
state.mode = DONE;
|
|
1978
1978
|
/* falls through */
|
|
@@ -1995,7 +1995,7 @@ function inflate(strm, flush2) {
|
|
|
1995
1995
|
strm.next_in = next;
|
|
1996
1996
|
strm.avail_in = have;
|
|
1997
1997
|
state.hold = hold;
|
|
1998
|
-
state.bits =
|
|
1998
|
+
state.bits = bits2;
|
|
1999
1999
|
if (state.wsize || _out !== strm.avail_out && state.mode < BAD$1 && (state.mode < CHECK || flush2 !== Z_FINISH$1)) {
|
|
2000
2000
|
if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) ;
|
|
2001
2001
|
}
|
|
@@ -2380,32 +2380,32 @@ function gen_bitlen(s, desc) {
|
|
|
2380
2380
|
var max_length = desc.stat_desc.max_length;
|
|
2381
2381
|
var h;
|
|
2382
2382
|
var n, m;
|
|
2383
|
-
var
|
|
2383
|
+
var bits2;
|
|
2384
2384
|
var xbits;
|
|
2385
2385
|
var f;
|
|
2386
2386
|
var overflow = 0;
|
|
2387
|
-
for (
|
|
2388
|
-
s.bl_count[
|
|
2387
|
+
for (bits2 = 0; bits2 <= MAX_BITS; bits2++) {
|
|
2388
|
+
s.bl_count[bits2] = 0;
|
|
2389
2389
|
}
|
|
2390
2390
|
tree[s.heap[s.heap_max] * 2 + 1] = 0;
|
|
2391
2391
|
for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
|
|
2392
2392
|
n = s.heap[h];
|
|
2393
|
-
|
|
2394
|
-
if (
|
|
2395
|
-
|
|
2393
|
+
bits2 = tree[tree[n * 2 + 1] * 2 + 1] + 1;
|
|
2394
|
+
if (bits2 > max_length) {
|
|
2395
|
+
bits2 = max_length;
|
|
2396
2396
|
overflow++;
|
|
2397
2397
|
}
|
|
2398
|
-
tree[n * 2 + 1] =
|
|
2398
|
+
tree[n * 2 + 1] = bits2;
|
|
2399
2399
|
if (n > max_code) {
|
|
2400
2400
|
continue;
|
|
2401
2401
|
}
|
|
2402
|
-
s.bl_count[
|
|
2402
|
+
s.bl_count[bits2]++;
|
|
2403
2403
|
xbits = 0;
|
|
2404
2404
|
if (n >= base) {
|
|
2405
2405
|
xbits = extra[n - base];
|
|
2406
2406
|
}
|
|
2407
2407
|
f = tree[n * 2];
|
|
2408
|
-
s.opt_len += f * (
|
|
2408
|
+
s.opt_len += f * (bits2 + xbits);
|
|
2409
2409
|
if (has_stree) {
|
|
2410
2410
|
s.static_len += f * (stree[n * 2 + 1] + xbits);
|
|
2411
2411
|
}
|
|
@@ -2414,25 +2414,25 @@ function gen_bitlen(s, desc) {
|
|
|
2414
2414
|
return;
|
|
2415
2415
|
}
|
|
2416
2416
|
do {
|
|
2417
|
-
|
|
2418
|
-
while (s.bl_count[
|
|
2419
|
-
|
|
2417
|
+
bits2 = max_length - 1;
|
|
2418
|
+
while (s.bl_count[bits2] === 0) {
|
|
2419
|
+
bits2--;
|
|
2420
2420
|
}
|
|
2421
|
-
s.bl_count[
|
|
2422
|
-
s.bl_count[
|
|
2421
|
+
s.bl_count[bits2]--;
|
|
2422
|
+
s.bl_count[bits2 + 1] += 2;
|
|
2423
2423
|
s.bl_count[max_length]--;
|
|
2424
2424
|
overflow -= 2;
|
|
2425
2425
|
} while (overflow > 0);
|
|
2426
|
-
for (
|
|
2427
|
-
n = s.bl_count[
|
|
2426
|
+
for (bits2 = max_length; bits2 !== 0; bits2--) {
|
|
2427
|
+
n = s.bl_count[bits2];
|
|
2428
2428
|
while (n !== 0) {
|
|
2429
2429
|
m = s.heap[--h];
|
|
2430
2430
|
if (m > max_code) {
|
|
2431
2431
|
continue;
|
|
2432
2432
|
}
|
|
2433
|
-
if (tree[m * 2 + 1] !==
|
|
2434
|
-
s.opt_len += (
|
|
2435
|
-
tree[m * 2 + 1] =
|
|
2433
|
+
if (tree[m * 2 + 1] !== bits2) {
|
|
2434
|
+
s.opt_len += (bits2 - tree[m * 2 + 1]) * tree[m * 2];
|
|
2435
|
+
tree[m * 2 + 1] = bits2;
|
|
2436
2436
|
}
|
|
2437
2437
|
n--;
|
|
2438
2438
|
}
|
|
@@ -2441,10 +2441,10 @@ function gen_bitlen(s, desc) {
|
|
|
2441
2441
|
function gen_codes(tree, max_code, bl_count) {
|
|
2442
2442
|
var next_code = new Array(MAX_BITS + 1);
|
|
2443
2443
|
var code = 0;
|
|
2444
|
-
var
|
|
2444
|
+
var bits2;
|
|
2445
2445
|
var n;
|
|
2446
|
-
for (
|
|
2447
|
-
next_code[
|
|
2446
|
+
for (bits2 = 1; bits2 <= MAX_BITS; bits2++) {
|
|
2447
|
+
next_code[bits2] = code = code + bl_count[bits2 - 1] << 1;
|
|
2448
2448
|
}
|
|
2449
2449
|
for (n = 0; n <= max_code; n++) {
|
|
2450
2450
|
var len = tree[n * 2 + 1];
|
|
@@ -2456,7 +2456,7 @@ function gen_codes(tree, max_code, bl_count) {
|
|
|
2456
2456
|
}
|
|
2457
2457
|
function tr_static_init() {
|
|
2458
2458
|
var n;
|
|
2459
|
-
var
|
|
2459
|
+
var bits2;
|
|
2460
2460
|
var length;
|
|
2461
2461
|
var code;
|
|
2462
2462
|
var dist;
|
|
@@ -2495,8 +2495,8 @@ function tr_static_init() {
|
|
|
2495
2495
|
_dist_code[256 + dist++] = code;
|
|
2496
2496
|
}
|
|
2497
2497
|
}
|
|
2498
|
-
for (
|
|
2499
|
-
bl_count[
|
|
2498
|
+
for (bits2 = 0; bits2 <= MAX_BITS; bits2++) {
|
|
2499
|
+
bl_count[bits2] = 0;
|
|
2500
2500
|
}
|
|
2501
2501
|
n = 0;
|
|
2502
2502
|
while (n <= 143) {
|
|
@@ -4578,23 +4578,23 @@ var string2buf2 = function(str) {
|
|
|
4578
4578
|
}
|
|
4579
4579
|
return buf;
|
|
4580
4580
|
};
|
|
4581
|
-
var utf8border2 = function(buf,
|
|
4581
|
+
var utf8border2 = function(buf, max2) {
|
|
4582
4582
|
var pos;
|
|
4583
|
-
|
|
4584
|
-
if (
|
|
4585
|
-
|
|
4583
|
+
max2 = max2 || buf.length;
|
|
4584
|
+
if (max2 > buf.length) {
|
|
4585
|
+
max2 = buf.length;
|
|
4586
4586
|
}
|
|
4587
|
-
pos =
|
|
4587
|
+
pos = max2 - 1;
|
|
4588
4588
|
while (pos >= 0 && (buf[pos] & 192) === 128) {
|
|
4589
4589
|
pos--;
|
|
4590
4590
|
}
|
|
4591
4591
|
if (pos < 0) {
|
|
4592
|
-
return
|
|
4592
|
+
return max2;
|
|
4593
4593
|
}
|
|
4594
4594
|
if (pos === 0) {
|
|
4595
|
-
return
|
|
4595
|
+
return max2;
|
|
4596
4596
|
}
|
|
4597
|
-
return pos + utf8len2(buf[pos]) >
|
|
4597
|
+
return pos + utf8len2(buf[pos]) > max2 ? pos : max2;
|
|
4598
4598
|
};
|
|
4599
4599
|
var buf2string2 = function(buf) {
|
|
4600
4600
|
var i, out, c, c_len;
|
|
@@ -4764,9 +4764,9 @@ function accumulate(helper, updateCallback) {
|
|
|
4764
4764
|
if (updateCallback) {
|
|
4765
4765
|
updateCallback(meta);
|
|
4766
4766
|
}
|
|
4767
|
-
}).on("error", function(
|
|
4767
|
+
}).on("error", function(err3) {
|
|
4768
4768
|
dataArray = [];
|
|
4769
|
-
reject(
|
|
4769
|
+
reject(err3);
|
|
4770
4770
|
}).on("end", function() {
|
|
4771
4771
|
try {
|
|
4772
4772
|
var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
|
|
@@ -6386,7 +6386,25 @@ for (i = 0; i < 32; ++i)
|
|
|
6386
6386
|
fdt[i] = 5;
|
|
6387
6387
|
var i;
|
|
6388
6388
|
var flm = /* @__PURE__ */ hMap(flt, 9, 0);
|
|
6389
|
+
var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
6389
6390
|
var fdm = /* @__PURE__ */ hMap(fdt, 5, 0);
|
|
6391
|
+
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
6392
|
+
var max = function(a) {
|
|
6393
|
+
var m = a[0];
|
|
6394
|
+
for (var i = 1; i < a.length; ++i) {
|
|
6395
|
+
if (a[i] > m)
|
|
6396
|
+
m = a[i];
|
|
6397
|
+
}
|
|
6398
|
+
return m;
|
|
6399
|
+
};
|
|
6400
|
+
var bits = function(d, p, m) {
|
|
6401
|
+
var o = p / 8 | 0;
|
|
6402
|
+
return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
|
|
6403
|
+
};
|
|
6404
|
+
var bits16 = function(d, p) {
|
|
6405
|
+
var o = p / 8 | 0;
|
|
6406
|
+
return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
|
|
6407
|
+
};
|
|
6390
6408
|
var shft = function(p) {
|
|
6391
6409
|
return (p + 7) / 8 | 0;
|
|
6392
6410
|
};
|
|
@@ -6397,6 +6415,174 @@ var slc = function(v, s, e) {
|
|
|
6397
6415
|
e = v.length;
|
|
6398
6416
|
return new u8(v.subarray(s, e));
|
|
6399
6417
|
};
|
|
6418
|
+
var ec = [
|
|
6419
|
+
"unexpected EOF",
|
|
6420
|
+
"invalid block type",
|
|
6421
|
+
"invalid length/literal",
|
|
6422
|
+
"invalid distance",
|
|
6423
|
+
"stream finished",
|
|
6424
|
+
"no stream handler",
|
|
6425
|
+
,
|
|
6426
|
+
// determined by compression function
|
|
6427
|
+
"no callback",
|
|
6428
|
+
"invalid UTF-8 data",
|
|
6429
|
+
"extra field too long",
|
|
6430
|
+
"date not in range 1980-2099",
|
|
6431
|
+
"filename too long",
|
|
6432
|
+
"stream finishing",
|
|
6433
|
+
"invalid zip data"
|
|
6434
|
+
// determined by unknown compression method
|
|
6435
|
+
];
|
|
6436
|
+
var err2 = function(ind, msg2, nt) {
|
|
6437
|
+
var e = new Error(msg2 || ec[ind]);
|
|
6438
|
+
e.code = ind;
|
|
6439
|
+
if (Error.captureStackTrace)
|
|
6440
|
+
Error.captureStackTrace(e, err2);
|
|
6441
|
+
if (!nt)
|
|
6442
|
+
throw e;
|
|
6443
|
+
return e;
|
|
6444
|
+
};
|
|
6445
|
+
var inflt = function(dat, st, buf, dict) {
|
|
6446
|
+
var sl = dat.length, dl = dict ? dict.length : 0;
|
|
6447
|
+
if (!sl || st.f && !st.l)
|
|
6448
|
+
return buf || new u8(0);
|
|
6449
|
+
var noBuf = !buf;
|
|
6450
|
+
var resize = noBuf || st.i != 2;
|
|
6451
|
+
var noSt = st.i;
|
|
6452
|
+
if (noBuf)
|
|
6453
|
+
buf = new u8(sl * 3);
|
|
6454
|
+
var cbuf = function(l2) {
|
|
6455
|
+
var bl = buf.length;
|
|
6456
|
+
if (l2 > bl) {
|
|
6457
|
+
var nbuf = new u8(Math.max(bl * 2, l2));
|
|
6458
|
+
nbuf.set(buf);
|
|
6459
|
+
buf = nbuf;
|
|
6460
|
+
}
|
|
6461
|
+
};
|
|
6462
|
+
var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
|
|
6463
|
+
var tbts = sl * 8;
|
|
6464
|
+
do {
|
|
6465
|
+
if (!lm) {
|
|
6466
|
+
final = bits(dat, pos, 1);
|
|
6467
|
+
var type = bits(dat, pos + 1, 3);
|
|
6468
|
+
pos += 3;
|
|
6469
|
+
if (!type) {
|
|
6470
|
+
var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
|
|
6471
|
+
if (t > sl) {
|
|
6472
|
+
if (noSt)
|
|
6473
|
+
err2(0);
|
|
6474
|
+
break;
|
|
6475
|
+
}
|
|
6476
|
+
if (resize)
|
|
6477
|
+
cbuf(bt + l);
|
|
6478
|
+
buf.set(dat.subarray(s, t), bt);
|
|
6479
|
+
st.b = bt += l, st.p = pos = t * 8, st.f = final;
|
|
6480
|
+
continue;
|
|
6481
|
+
} else if (type == 1)
|
|
6482
|
+
lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
|
|
6483
|
+
else if (type == 2) {
|
|
6484
|
+
var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
|
|
6485
|
+
var tl = hLit + bits(dat, pos + 5, 31) + 1;
|
|
6486
|
+
pos += 14;
|
|
6487
|
+
var ldt = new u8(tl);
|
|
6488
|
+
var clt = new u8(19);
|
|
6489
|
+
for (var i = 0; i < hcLen; ++i) {
|
|
6490
|
+
clt[clim[i]] = bits(dat, pos + i * 3, 7);
|
|
6491
|
+
}
|
|
6492
|
+
pos += hcLen * 3;
|
|
6493
|
+
var clb = max(clt), clbmsk = (1 << clb) - 1;
|
|
6494
|
+
var clm = hMap(clt, clb, 1);
|
|
6495
|
+
for (var i = 0; i < tl; ) {
|
|
6496
|
+
var r = clm[bits(dat, pos, clbmsk)];
|
|
6497
|
+
pos += r & 15;
|
|
6498
|
+
var s = r >> 4;
|
|
6499
|
+
if (s < 16) {
|
|
6500
|
+
ldt[i++] = s;
|
|
6501
|
+
} else {
|
|
6502
|
+
var c = 0, n = 0;
|
|
6503
|
+
if (s == 16)
|
|
6504
|
+
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
|
|
6505
|
+
else if (s == 17)
|
|
6506
|
+
n = 3 + bits(dat, pos, 7), pos += 3;
|
|
6507
|
+
else if (s == 18)
|
|
6508
|
+
n = 11 + bits(dat, pos, 127), pos += 7;
|
|
6509
|
+
while (n--)
|
|
6510
|
+
ldt[i++] = c;
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
|
6514
|
+
lbt = max(lt);
|
|
6515
|
+
dbt = max(dt);
|
|
6516
|
+
lm = hMap(lt, lbt, 1);
|
|
6517
|
+
dm = hMap(dt, dbt, 1);
|
|
6518
|
+
} else
|
|
6519
|
+
err2(1);
|
|
6520
|
+
if (pos > tbts) {
|
|
6521
|
+
if (noSt)
|
|
6522
|
+
err2(0);
|
|
6523
|
+
break;
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
if (resize)
|
|
6527
|
+
cbuf(bt + 131072);
|
|
6528
|
+
var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
|
|
6529
|
+
var lpos = pos;
|
|
6530
|
+
for (; ; lpos = pos) {
|
|
6531
|
+
var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
|
|
6532
|
+
pos += c & 15;
|
|
6533
|
+
if (pos > tbts) {
|
|
6534
|
+
if (noSt)
|
|
6535
|
+
err2(0);
|
|
6536
|
+
break;
|
|
6537
|
+
}
|
|
6538
|
+
if (!c)
|
|
6539
|
+
err2(2);
|
|
6540
|
+
if (sym < 256)
|
|
6541
|
+
buf[bt++] = sym;
|
|
6542
|
+
else if (sym == 256) {
|
|
6543
|
+
lpos = pos, lm = null;
|
|
6544
|
+
break;
|
|
6545
|
+
} else {
|
|
6546
|
+
var add = sym - 254;
|
|
6547
|
+
if (sym > 264) {
|
|
6548
|
+
var i = sym - 257, b = fleb[i];
|
|
6549
|
+
add = bits(dat, pos, (1 << b) - 1) + fl[i];
|
|
6550
|
+
pos += b;
|
|
6551
|
+
}
|
|
6552
|
+
var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
|
|
6553
|
+
if (!d)
|
|
6554
|
+
err2(3);
|
|
6555
|
+
pos += d & 15;
|
|
6556
|
+
var dt = fd[dsym];
|
|
6557
|
+
if (dsym > 3) {
|
|
6558
|
+
var b = fdeb[dsym];
|
|
6559
|
+
dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
|
|
6560
|
+
}
|
|
6561
|
+
if (pos > tbts) {
|
|
6562
|
+
if (noSt)
|
|
6563
|
+
err2(0);
|
|
6564
|
+
break;
|
|
6565
|
+
}
|
|
6566
|
+
if (resize)
|
|
6567
|
+
cbuf(bt + 131072);
|
|
6568
|
+
var end2 = bt + add;
|
|
6569
|
+
if (bt < dt) {
|
|
6570
|
+
var shift = dl - dt, dend = Math.min(dt, end2);
|
|
6571
|
+
if (shift + bt < 0)
|
|
6572
|
+
err2(3);
|
|
6573
|
+
for (; bt < dend; ++bt)
|
|
6574
|
+
buf[bt] = dict[shift + bt];
|
|
6575
|
+
}
|
|
6576
|
+
for (; bt < end2; ++bt)
|
|
6577
|
+
buf[bt] = buf[bt - dt];
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
st.l = lm, st.p = lpos, st.b = bt, st.f = final;
|
|
6581
|
+
if (lm)
|
|
6582
|
+
final = 1, st.m = lbt, st.d = dm, st.n = dbt;
|
|
6583
|
+
} while (!final);
|
|
6584
|
+
return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
|
|
6585
|
+
};
|
|
6400
6586
|
var wbits = function(d, p, v) {
|
|
6401
6587
|
v <<= p & 7;
|
|
6402
6588
|
var o = p / 8 | 0;
|
|
@@ -6715,6 +6901,43 @@ var dopt = function(dat, opt, pre, post, st) {
|
|
|
6715
6901
|
function deflateSync(data, opts) {
|
|
6716
6902
|
return dopt(data, opts || {}, 0, 0);
|
|
6717
6903
|
}
|
|
6904
|
+
var Inflate3 = /* @__PURE__ */ (function() {
|
|
6905
|
+
function Inflate4(opts, cb) {
|
|
6906
|
+
if (typeof opts == "function")
|
|
6907
|
+
cb = opts, opts = {};
|
|
6908
|
+
this.ondata = cb;
|
|
6909
|
+
var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
|
|
6910
|
+
this.s = { i: 0, b: dict ? dict.length : 0 };
|
|
6911
|
+
this.o = new u8(32768);
|
|
6912
|
+
this.p = new u8(0);
|
|
6913
|
+
if (dict)
|
|
6914
|
+
this.o.set(dict);
|
|
6915
|
+
}
|
|
6916
|
+
Inflate4.prototype.e = function(c) {
|
|
6917
|
+
if (!this.ondata)
|
|
6918
|
+
err2(5);
|
|
6919
|
+
if (this.d)
|
|
6920
|
+
err2(4);
|
|
6921
|
+
if (!this.p.length)
|
|
6922
|
+
this.p = c;
|
|
6923
|
+
else if (c.length) {
|
|
6924
|
+
var n = new u8(this.p.length + c.length);
|
|
6925
|
+
n.set(this.p), n.set(c, this.p.length), this.p = n;
|
|
6926
|
+
}
|
|
6927
|
+
};
|
|
6928
|
+
Inflate4.prototype.c = function(final) {
|
|
6929
|
+
this.s.i = +(this.d = final || false);
|
|
6930
|
+
var bts = this.s.b;
|
|
6931
|
+
var dt = inflt(this.p, this.s, this.o);
|
|
6932
|
+
this.ondata(slc(dt, bts, this.s.b), this.d);
|
|
6933
|
+
this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
|
|
6934
|
+
this.p = slc(this.p, this.s.p / 8 | 0), this.s.p &= 7;
|
|
6935
|
+
};
|
|
6936
|
+
Inflate4.prototype.push = function(chunk, final) {
|
|
6937
|
+
this.e(chunk), this.c(final);
|
|
6938
|
+
};
|
|
6939
|
+
return Inflate4;
|
|
6940
|
+
})();
|
|
6718
6941
|
var td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
|
|
6719
6942
|
var tds = 0;
|
|
6720
6943
|
try {
|
|
@@ -7084,8 +7307,14 @@ function insideArchive(archive, segments, host, withFragment, directory) {
|
|
|
7084
7307
|
|
|
7085
7308
|
// ../../node_modules/@mdzip/core-js/dist/mdz-core.js
|
|
7086
7309
|
var PRODUCER_SPEC_VERSION = MDZ_SPEC_VERSION;
|
|
7087
|
-
var CORE_LIBRARY_VERSION = "2.
|
|
7310
|
+
var CORE_LIBRARY_VERSION = "2.2.1";
|
|
7088
7311
|
var CORE_LIBRARY_URL = "https://github.com/mdzip-project/mdzip-core-js";
|
|
7312
|
+
var MDZ_MAX_ENTRIES = 1e5;
|
|
7313
|
+
var MDZ_MAX_ENTRY_UNCOMPRESSED_BYTES = 1024 ** 3;
|
|
7314
|
+
var MDZ_MAX_TOTAL_UNCOMPRESSED_BYTES = 4 * 1024 ** 3;
|
|
7315
|
+
var MDZ_MAX_COMPRESSION_RATIO = 1e3;
|
|
7316
|
+
var COMPRESSION_RATIO_APPLIES_ABOVE_BYTES = 1024 * 1024;
|
|
7317
|
+
var INFLATE_STEP_BYTES = 8192;
|
|
7089
7318
|
function isSymlinkEntry(entry) {
|
|
7090
7319
|
const mode = entry?.unixPermissions;
|
|
7091
7320
|
return typeof mode === "number" && (mode & 61440) === 40960;
|
|
@@ -7138,6 +7367,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
7138
7367
|
if (zipFactory) {
|
|
7139
7368
|
const zip2 = await _MdzArchiveCore.loadOrThrowZipInvalid(() => factory.loadAsync(input));
|
|
7140
7369
|
_MdzArchiveCore.checkEntryNames(Object.keys(zip2.files));
|
|
7370
|
+
_MdzArchiveCore.checkEntryCount(Object.keys(zip2.files).length);
|
|
7141
7371
|
return new _MdzArchiveCore(zip2);
|
|
7142
7372
|
}
|
|
7143
7373
|
const bytes = await _MdzArchiveCore.readArchiveInputBytes(input);
|
|
@@ -7150,6 +7380,8 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
7150
7380
|
throw mdzError("ERR_ZIP_INVALID", `entry '${entry.name}' uses compression method ${entry.method}; MDZip allows 0 (stored) and 8 (DEFLATE) (\xA74)`);
|
|
7151
7381
|
}
|
|
7152
7382
|
}
|
|
7383
|
+
_MdzArchiveCore.checkResourceLimits(raw);
|
|
7384
|
+
_MdzArchiveCore.checkCentralDirectoryVisible(raw, zip);
|
|
7153
7385
|
names = raw.map((entry) => entry.name);
|
|
7154
7386
|
} catch (error2) {
|
|
7155
7387
|
if (!(error2 instanceof Error) || !error2.message.startsWith("ERR_ZIP_UNSUPPORTED"))
|
|
@@ -7168,6 +7400,53 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
7168
7400
|
throw mdzError("ERR_ZIP_INVALID", "The file is not a valid ZIP archive.", { cause: error2 });
|
|
7169
7401
|
}
|
|
7170
7402
|
}
|
|
7403
|
+
static checkEntryCount(count) {
|
|
7404
|
+
if (count > MDZ_MAX_ENTRIES) {
|
|
7405
|
+
throw mdzError("ERR_LIMIT_EXCEEDED", `The archive has ${count} entries (limit ${MDZ_MAX_ENTRIES}).`);
|
|
7406
|
+
}
|
|
7407
|
+
}
|
|
7408
|
+
/**
|
|
7409
|
+
* Rejects an archive whose declared sizes exceed the built-in limits (`ERR_LIMIT_EXCEEDED`, §13.1),
|
|
7410
|
+
* before anything is decompressed. Actual sizes are checked again on every read, since declared
|
|
7411
|
+
* sizes can lie.
|
|
7412
|
+
*/
|
|
7413
|
+
static checkResourceLimits(raw) {
|
|
7414
|
+
_MdzArchiveCore.checkEntryCount(raw.length);
|
|
7415
|
+
let total = 0;
|
|
7416
|
+
for (const entry of raw) {
|
|
7417
|
+
if (entry.name.endsWith("/"))
|
|
7418
|
+
continue;
|
|
7419
|
+
const size = entry.uncompressedSize;
|
|
7420
|
+
if (size > MDZ_MAX_ENTRY_UNCOMPRESSED_BYTES) {
|
|
7421
|
+
throw mdzError("ERR_LIMIT_EXCEEDED", `'${entry.name}' is ${size} bytes (limit ${MDZ_MAX_ENTRY_UNCOMPRESSED_BYTES}).`);
|
|
7422
|
+
}
|
|
7423
|
+
if (size > COMPRESSION_RATIO_APPLIES_ABOVE_BYTES && entry.compressedSize > 0 && size / entry.compressedSize > MDZ_MAX_COMPRESSION_RATIO) {
|
|
7424
|
+
throw mdzError("ERR_LIMIT_EXCEEDED", `'${entry.name}' has compression ratio ${Math.round(size / entry.compressedSize)}:1 (limit ${MDZ_MAX_COMPRESSION_RATIO}:1).`);
|
|
7425
|
+
}
|
|
7426
|
+
total += size;
|
|
7427
|
+
if (total > MDZ_MAX_TOTAL_UNCOMPRESSED_BYTES) {
|
|
7428
|
+
throw mdzError("ERR_LIMIT_EXCEEDED", `The archive's total uncompressed size exceeds ${MDZ_MAX_TOTAL_UNCOMPRESSED_BYTES} bytes.`);
|
|
7429
|
+
}
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
/**
|
|
7433
|
+
* The central directory governs (§4): every entry it lists must be one JSZip exposes, and no two
|
|
7434
|
+
* may share data. Otherwise entries would be hidden silently (`ERR_ZIP_INVALID`).
|
|
7435
|
+
*/
|
|
7436
|
+
static checkCentralDirectoryVisible(raw, zip) {
|
|
7437
|
+
const visible = new Set(Object.keys(zip.files).map((name) => _MdzArchiveCore.normalizePath(name)));
|
|
7438
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
7439
|
+
for (const entry of raw) {
|
|
7440
|
+
const other = offsets.get(entry.localOffset);
|
|
7441
|
+
if (other !== void 0) {
|
|
7442
|
+
throw mdzError("ERR_ZIP_INVALID", `'${entry.name}' and '${other}' share the same data in the archive.`);
|
|
7443
|
+
}
|
|
7444
|
+
offsets.set(entry.localOffset, entry.name);
|
|
7445
|
+
if (!visible.has(entry.name)) {
|
|
7446
|
+
throw mdzError("ERR_ZIP_INVALID", `'${entry.name}' is in the central directory but can't be read.`);
|
|
7447
|
+
}
|
|
7448
|
+
}
|
|
7449
|
+
}
|
|
7171
7450
|
/** Rejects NFC-duplicate entries and files that are also directories (§5.4, §13.1): never picks one. */
|
|
7172
7451
|
static checkEntryNames(names) {
|
|
7173
7452
|
const problem = entrySetProblem(names);
|
|
@@ -7297,7 +7576,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
7297
7576
|
normalizedWrites.delete(key);
|
|
7298
7577
|
}
|
|
7299
7578
|
const changing = normalizedWrites.size > 0 || normalizedRemovals.size > 0;
|
|
7300
|
-
const existingManifest = await _MdzArchiveCore.readExistingManifestObject(archive
|
|
7579
|
+
const existingManifest = await _MdzArchiveCore.readExistingManifestObject(archive, changing);
|
|
7301
7580
|
const entryPointBefore = MdzPackagerCore.resolveEntryPoint(existingPaths, existingManifest);
|
|
7302
7581
|
const manifestWrite = normalizedWrites.get("manifest.json");
|
|
7303
7582
|
let manifestObject = null;
|
|
@@ -8048,8 +8327,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8048
8327
|
* @param path - Archive-relative file path.
|
|
8049
8328
|
*/
|
|
8050
8329
|
async readText(path) {
|
|
8051
|
-
|
|
8052
|
-
return String(await entry.async("text"));
|
|
8330
|
+
return this.readEntryText(this.getFileEntryOrThrow(path));
|
|
8053
8331
|
}
|
|
8054
8332
|
/**
|
|
8055
8333
|
* Reads raw bytes from an entry.
|
|
@@ -8057,9 +8335,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8057
8335
|
* @param path - Archive-relative file path.
|
|
8058
8336
|
*/
|
|
8059
8337
|
async readBytes(path) {
|
|
8060
|
-
|
|
8061
|
-
const out = await entry.async("arraybuffer");
|
|
8062
|
-
return new Uint8Array(out);
|
|
8338
|
+
return this.readEntryData(this.getFileEntryOrThrow(path));
|
|
8063
8339
|
}
|
|
8064
8340
|
/**
|
|
8065
8341
|
* Reads entry content as raw base64 (no data URI prefix).
|
|
@@ -8067,8 +8343,100 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8067
8343
|
* @param path - Archive-relative file path.
|
|
8068
8344
|
*/
|
|
8069
8345
|
async readBase64(path) {
|
|
8070
|
-
const
|
|
8071
|
-
|
|
8346
|
+
const bytes = await this.readEntryData(this.getFileEntryOrThrow(path));
|
|
8347
|
+
let binary2 = "";
|
|
8348
|
+
for (let i = 0; i < bytes.length; i += 32768) {
|
|
8349
|
+
binary2 += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
8350
|
+
}
|
|
8351
|
+
return btoa(binary2);
|
|
8352
|
+
}
|
|
8353
|
+
/** Central directory records by normalized name, from the raw bytes; null when unavailable. */
|
|
8354
|
+
rawEntryIndex;
|
|
8355
|
+
getRawEntry(name) {
|
|
8356
|
+
if (this.rawEntryIndex === void 0) {
|
|
8357
|
+
this.rawEntryIndex = null;
|
|
8358
|
+
if (this.rawBytes) {
|
|
8359
|
+
try {
|
|
8360
|
+
this.rawEntryIndex = new Map(_MdzArchiveCore.parseRawZipEntries(this.rawBytes).map((e) => [e.name, e]));
|
|
8361
|
+
} catch (error2) {
|
|
8362
|
+
if (!(error2 instanceof Error) || !error2.message.startsWith("ERR_ZIP_UNSUPPORTED"))
|
|
8363
|
+
throw error2;
|
|
8364
|
+
}
|
|
8365
|
+
}
|
|
8366
|
+
}
|
|
8367
|
+
return this.rawEntryIndex?.get(_MdzArchiveCore.normalizePath(name));
|
|
8368
|
+
}
|
|
8369
|
+
/**
|
|
8370
|
+
* An entry's bytes. Decompressed from the archive bytes when they're available, stopping at the
|
|
8371
|
+
* declared size and checking the CRC-32: data past the declared size is `ERR_LIMIT_EXCEEDED`;
|
|
8372
|
+
* short, mismatched or undecompressable data is `ERR_ZIP_INVALID` (§13.1). Never returns corrupt
|
|
8373
|
+
* data as success. Archives opened with a custom ZIP factory are read through it.
|
|
8374
|
+
*/
|
|
8375
|
+
async readEntryData(entry) {
|
|
8376
|
+
const raw = this.getRawEntry(entry.name);
|
|
8377
|
+
if (raw && this.rawBytes) {
|
|
8378
|
+
return _MdzArchiveCore.inflateEntryChecked(this.rawBytes, raw);
|
|
8379
|
+
}
|
|
8380
|
+
try {
|
|
8381
|
+
return new Uint8Array(await entry.async("arraybuffer"));
|
|
8382
|
+
} catch (error2) {
|
|
8383
|
+
throw mdzError("ERR_ZIP_INVALID", `'${entry.name}' is corrupt.`, { cause: error2 });
|
|
8384
|
+
}
|
|
8385
|
+
}
|
|
8386
|
+
/** An entry's UTF-8 text, checked as {@link readEntryData} describes. A leading BOM is kept. */
|
|
8387
|
+
async readEntryText(entry) {
|
|
8388
|
+
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(await this.readEntryData(entry));
|
|
8389
|
+
}
|
|
8390
|
+
static inflateEntryChecked(source, raw) {
|
|
8391
|
+
const corrupt = (detail, cause) => mdzError("ERR_ZIP_INVALID", `'${raw.name}' is corrupt: ${detail}.`, cause === void 0 ? void 0 : { cause });
|
|
8392
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
8393
|
+
const local = raw.localOffset;
|
|
8394
|
+
if (local + 30 > source.length || view.getUint32(local, true) !== 67324752) {
|
|
8395
|
+
throw corrupt("its local header is missing");
|
|
8396
|
+
}
|
|
8397
|
+
const start = local + 30 + view.getUint16(local + 26, true) + view.getUint16(local + 28, true);
|
|
8398
|
+
const end2 = start + raw.compressedSize;
|
|
8399
|
+
if (end2 > source.length)
|
|
8400
|
+
throw corrupt("its data runs past the end of the archive");
|
|
8401
|
+
const compressed = source.subarray(start, end2);
|
|
8402
|
+
const declared = raw.uncompressedSize;
|
|
8403
|
+
let out;
|
|
8404
|
+
if (raw.method === 0) {
|
|
8405
|
+
if (compressed.length !== declared)
|
|
8406
|
+
throw corrupt("its stored size does not match its declared size");
|
|
8407
|
+
out = compressed.slice();
|
|
8408
|
+
} else {
|
|
8409
|
+
const buffer = new Uint8Array(declared);
|
|
8410
|
+
out = buffer;
|
|
8411
|
+
let filled = 0;
|
|
8412
|
+
let overflow = false;
|
|
8413
|
+
const inflater = new Inflate3((chunk) => {
|
|
8414
|
+
if (filled + chunk.length > declared) {
|
|
8415
|
+
overflow = true;
|
|
8416
|
+
throw new Error("overflow");
|
|
8417
|
+
}
|
|
8418
|
+
buffer.set(chunk, filled);
|
|
8419
|
+
filled += chunk.length;
|
|
8420
|
+
});
|
|
8421
|
+
try {
|
|
8422
|
+
let offset = 0;
|
|
8423
|
+
do {
|
|
8424
|
+
const next = Math.min(offset + INFLATE_STEP_BYTES, compressed.length);
|
|
8425
|
+
inflater.push(compressed.subarray(offset, next), next >= compressed.length);
|
|
8426
|
+
offset = next;
|
|
8427
|
+
} while (offset < compressed.length);
|
|
8428
|
+
} catch (error2) {
|
|
8429
|
+
if (overflow) {
|
|
8430
|
+
throw mdzError("ERR_LIMIT_EXCEEDED", `'${raw.name}' decompresses to more than its declared size.`);
|
|
8431
|
+
}
|
|
8432
|
+
throw corrupt("its compressed data is invalid", error2);
|
|
8433
|
+
}
|
|
8434
|
+
if (filled !== declared)
|
|
8435
|
+
throw corrupt("it decompresses to less than its declared size");
|
|
8436
|
+
}
|
|
8437
|
+
if (_MdzArchiveCore.crc32(out) !== raw.crc >>> 0)
|
|
8438
|
+
throw corrupt("its checksum does not match");
|
|
8439
|
+
return out;
|
|
8072
8440
|
}
|
|
8073
8441
|
/**
|
|
8074
8442
|
* Reads entry content and returns a data URI string.
|
|
@@ -8240,7 +8608,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8240
8608
|
_MdzArchiveCore.manifestCache.set(this.zip, null);
|
|
8241
8609
|
return null;
|
|
8242
8610
|
}
|
|
8243
|
-
const { manifest, duplicateMembers } = parseManifestText(
|
|
8611
|
+
const { manifest, duplicateMembers } = parseManifestText(await this.readEntryText(entry));
|
|
8244
8612
|
const ignoredFields = checkManifest(manifest);
|
|
8245
8613
|
_MdzArchiveCore.checkLegacyMdzField(manifest);
|
|
8246
8614
|
const normalized = { ...manifest };
|
|
@@ -8436,7 +8804,8 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8436
8804
|
}
|
|
8437
8805
|
/**
|
|
8438
8806
|
* Extracts every image reference target found in a block of Markdown text,
|
|
8439
|
-
* from both `` syntax and raw `<img src="target">` HTML tags
|
|
8807
|
+
* from both `` syntax and raw `<img src="target">` HTML tags,
|
|
8808
|
+
* ignoring fenced/indented code blocks and inline code spans
|
|
8440
8809
|
* (used for sizing/alignment control Markdown syntax can't express).
|
|
8441
8810
|
* Targets are returned raw/unresolved — relative to whatever base the
|
|
8442
8811
|
* caller's markdown lives at — with surrounding `<...>` wrapping and
|
|
@@ -8450,6 +8819,7 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8450
8819
|
* time, leaving other independent copies elsewhere still `![]()`-only.
|
|
8451
8820
|
*/
|
|
8452
8821
|
static extractImageReferences(markdown) {
|
|
8822
|
+
markdown = _MdzArchiveCore.maskMarkdownCode(markdown);
|
|
8453
8823
|
const refs = [];
|
|
8454
8824
|
const mdRe = new RegExp(_MdzArchiveCore.MARKDOWN_IMAGE_REF_RE.source, "g");
|
|
8455
8825
|
let match;
|
|
@@ -8468,6 +8838,141 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8468
8838
|
}
|
|
8469
8839
|
return refs;
|
|
8470
8840
|
}
|
|
8841
|
+
// CommonMark HTML blocks (spec section 4.6). Markdown inside one is raw
|
|
8842
|
+
// HTML, never an image, but an <img src> there still is one (#11).
|
|
8843
|
+
// Conditions 1-5 end on the line matching `end`; 6 and 7 at a blank line.
|
|
8844
|
+
static HTML_BLOCK_STARTS = [
|
|
8845
|
+
{ start: /^ {0,3}<(?:pre|script|style|textarea)(?:[\s>]|$)/i, end: /<\/(?:pre|script|style|textarea)>/i, interruptsParagraph: true },
|
|
8846
|
+
{ start: /^ {0,3}<!--/, end: /-->/, interruptsParagraph: true },
|
|
8847
|
+
{ start: /^ {0,3}<\?/, end: /\?>/, interruptsParagraph: true },
|
|
8848
|
+
{ start: /^ {0,3}<![A-Za-z]/, end: />/, interruptsParagraph: true },
|
|
8849
|
+
{ start: /^ {0,3}<!\[CDATA\[/, end: /\]\]>/, interruptsParagraph: true },
|
|
8850
|
+
{
|
|
8851
|
+
start: /^ {0,3}<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[\s>]|\/>|$)/i,
|
|
8852
|
+
interruptsParagraph: true
|
|
8853
|
+
},
|
|
8854
|
+
{
|
|
8855
|
+
start: /^ {0,3}(?:<(?!(?:pre|script|style|textarea)[\s/>])[A-Za-z][A-Za-z0-9-]*(?:\s+[A-Za-z_:][\w.:-]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*\/?>|<\/[A-Za-z][A-Za-z0-9-]*\s*>)[ \t]*$/i,
|
|
8856
|
+
interruptsParagraph: false
|
|
8857
|
+
}
|
|
8858
|
+
];
|
|
8859
|
+
/** Hide code, and Markdown image syntax in HTML blocks, before scanning images, preserving newlines and source positions. */
|
|
8860
|
+
static maskMarkdownCode(markdown) {
|
|
8861
|
+
const blank = (text) => text.replace(/[^\r\n]/g, " ");
|
|
8862
|
+
const blankMarkdownImages = (text) => text.replace(new RegExp(_MdzArchiveCore.MARKDOWN_IMAGE_REF_RE.source, "g"), blank);
|
|
8863
|
+
let fence;
|
|
8864
|
+
let indented = false;
|
|
8865
|
+
let paragraph = false;
|
|
8866
|
+
let html;
|
|
8867
|
+
const htmlRanges = [];
|
|
8868
|
+
let offset = 0;
|
|
8869
|
+
const inHtmlBlock = (line) => {
|
|
8870
|
+
htmlRanges.push([offset, offset + line.length]);
|
|
8871
|
+
return blankMarkdownImages(line);
|
|
8872
|
+
};
|
|
8873
|
+
const blocks = markdown.split(/(?<=\n)/).map((line) => {
|
|
8874
|
+
const content = line.replace(/[\r\n]+$/, "");
|
|
8875
|
+
try {
|
|
8876
|
+
return maskLine(line, content);
|
|
8877
|
+
} finally {
|
|
8878
|
+
offset += line.length;
|
|
8879
|
+
}
|
|
8880
|
+
}).join("");
|
|
8881
|
+
function maskLine(line, content) {
|
|
8882
|
+
if (html !== void 0) {
|
|
8883
|
+
if (html === null) {
|
|
8884
|
+
if (/^[ \t]*$/.test(content)) {
|
|
8885
|
+
html = void 0;
|
|
8886
|
+
paragraph = false;
|
|
8887
|
+
return line;
|
|
8888
|
+
}
|
|
8889
|
+
} else if (html.test(content)) {
|
|
8890
|
+
html = void 0;
|
|
8891
|
+
paragraph = false;
|
|
8892
|
+
}
|
|
8893
|
+
return inHtmlBlock(line);
|
|
8894
|
+
}
|
|
8895
|
+
return maskMarkdownLine(line, content);
|
|
8896
|
+
}
|
|
8897
|
+
function maskMarkdownLine(line, content) {
|
|
8898
|
+
if (fence) {
|
|
8899
|
+
const close = /^ {0,3}(`+|~+)[ \t]*$/.exec(content);
|
|
8900
|
+
if (close && close[1][0] === fence[0] && close[1].length >= fence.length)
|
|
8901
|
+
fence = void 0;
|
|
8902
|
+
return blank(line);
|
|
8903
|
+
}
|
|
8904
|
+
const open = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(content);
|
|
8905
|
+
if (open && (open[1][0] !== "`" || !open[2].includes("`"))) {
|
|
8906
|
+
fence = open[1];
|
|
8907
|
+
paragraph = false;
|
|
8908
|
+
indented = false;
|
|
8909
|
+
return blank(line);
|
|
8910
|
+
}
|
|
8911
|
+
if (/^[ \t]*$/.test(content)) {
|
|
8912
|
+
paragraph = false;
|
|
8913
|
+
return line;
|
|
8914
|
+
}
|
|
8915
|
+
if (/^(?: {4}| {0,3}\t)/.test(content) && (indented || !paragraph)) {
|
|
8916
|
+
indented = true;
|
|
8917
|
+
return blank(line);
|
|
8918
|
+
}
|
|
8919
|
+
indented = false;
|
|
8920
|
+
for (const kind of _MdzArchiveCore.HTML_BLOCK_STARTS) {
|
|
8921
|
+
if (paragraph && !kind.interruptsParagraph)
|
|
8922
|
+
continue;
|
|
8923
|
+
const start = kind.start.exec(content);
|
|
8924
|
+
if (!start)
|
|
8925
|
+
continue;
|
|
8926
|
+
html = kind.end && kind.end.test(content.slice(start[0].length)) ? void 0 : kind.end ?? null;
|
|
8927
|
+
paragraph = false;
|
|
8928
|
+
return inHtmlBlock(line);
|
|
8929
|
+
}
|
|
8930
|
+
paragraph = true;
|
|
8931
|
+
return line;
|
|
8932
|
+
}
|
|
8933
|
+
let rangeIndex = 0;
|
|
8934
|
+
const runs = [...blocks.matchAll(/`+/g)].filter((run) => {
|
|
8935
|
+
while (rangeIndex < htmlRanges.length && htmlRanges[rangeIndex][1] <= run.index)
|
|
8936
|
+
rangeIndex++;
|
|
8937
|
+
return rangeIndex >= htmlRanges.length || htmlRanges[rangeIndex][0] > run.index;
|
|
8938
|
+
});
|
|
8939
|
+
const next = /* @__PURE__ */ new Map();
|
|
8940
|
+
const closing = /* @__PURE__ */ new Map();
|
|
8941
|
+
for (let i = runs.length - 1; i >= 0; i--) {
|
|
8942
|
+
const length = runs[i][0].length;
|
|
8943
|
+
const following = next.get(length);
|
|
8944
|
+
if (following !== void 0)
|
|
8945
|
+
closing.set(i, following);
|
|
8946
|
+
next.set(length, i);
|
|
8947
|
+
}
|
|
8948
|
+
const pieces = [];
|
|
8949
|
+
const tags = [...blocks.matchAll(/<[A-Za-z/](?:[^>"']|"[^"]*"|'[^']*')*>/g)];
|
|
8950
|
+
let tagIndex = 0;
|
|
8951
|
+
let copied = 0;
|
|
8952
|
+
for (let i = 0; i < runs.length; i++) {
|
|
8953
|
+
const start = runs[i].index;
|
|
8954
|
+
while (tagIndex < tags.length && tags[tagIndex].index + tags[tagIndex][0].length <= start)
|
|
8955
|
+
tagIndex++;
|
|
8956
|
+
if (tagIndex < tags.length && tags[tagIndex].index <= start)
|
|
8957
|
+
continue;
|
|
8958
|
+
let slashes = 0;
|
|
8959
|
+
for (let p = start - 1; p >= 0 && blocks[p] === "\\"; p--)
|
|
8960
|
+
slashes++;
|
|
8961
|
+
if (slashes % 2)
|
|
8962
|
+
continue;
|
|
8963
|
+
const endRun = closing.get(i);
|
|
8964
|
+
if (endRun === void 0)
|
|
8965
|
+
continue;
|
|
8966
|
+
const end2 = runs[endRun].index + runs[endRun][0].length;
|
|
8967
|
+
if (/\r?\n[ \t]*\r?\n/.test(blocks.slice(start, end2)))
|
|
8968
|
+
continue;
|
|
8969
|
+
pieces.push(blocks.slice(copied, start), blank(blocks.slice(start, end2)));
|
|
8970
|
+
copied = end2;
|
|
8971
|
+
i = endRun;
|
|
8972
|
+
}
|
|
8973
|
+
pieces.push(blocks.slice(copied));
|
|
8974
|
+
return pieces.join("");
|
|
8975
|
+
}
|
|
8471
8976
|
static cleanMarkdownLinkTarget(raw) {
|
|
8472
8977
|
let target = raw.trim();
|
|
8473
8978
|
if (target.startsWith("<") && target.endsWith(">")) {
|
|
@@ -8504,11 +9009,11 @@ var MdzArchiveCore = class _MdzArchiveCore {
|
|
|
8504
9009
|
static normaliseLf(content) {
|
|
8505
9010
|
return content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
8506
9011
|
}
|
|
8507
|
-
static async readExistingManifestObject(
|
|
8508
|
-
const manifestEntry = Object.entries(zip.files).find(([p, entry]) => _MdzArchiveCore.normalizePath(p) === "manifest.json" && !entry.dir)?.[1];
|
|
9012
|
+
static async readExistingManifestObject(archive, requireValid) {
|
|
9013
|
+
const manifestEntry = Object.entries(archive.zip.files).find(([p, entry]) => _MdzArchiveCore.normalizePath(p) === "manifest.json" && !entry.dir)?.[1];
|
|
8509
9014
|
if (!manifestEntry)
|
|
8510
9015
|
return null;
|
|
8511
|
-
const raw = await
|
|
9016
|
+
const raw = await archive.readEntryText(manifestEntry);
|
|
8512
9017
|
try {
|
|
8513
9018
|
const parsed = JSON.parse(String(raw));
|
|
8514
9019
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
@@ -9336,8 +9841,8 @@ function respondBytes(id, bytes) {
|
|
|
9336
9841
|
ctx.postMessage({ id, ok: true, result: buffer }, [buffer]);
|
|
9337
9842
|
}
|
|
9338
9843
|
function respondError(id, error2) {
|
|
9339
|
-
const
|
|
9340
|
-
ctx.postMessage({ id, ok: false, error: { name:
|
|
9844
|
+
const err3 = error2 instanceof Error ? error2 : new Error(String(error2));
|
|
9845
|
+
ctx.postMessage({ id, ok: false, error: { name: err3.name, message: err3.message } });
|
|
9341
9846
|
}
|
|
9342
9847
|
ctx.onmessage = (event) => {
|
|
9343
9848
|
const request = event.data;
|