Skip to content

Commit

Permalink
Improve packed header checks
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Jan 23, 2025
1 parent c5862f7 commit 75c24e0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/io.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1982,9 +1982,7 @@ function LZ4_uncompress(input, output, sIdx, eIdx) {
* @return {Promise} with unzipped content
* @private */
async function R__unzip(arr, tgtsize, noalert, src_shift) {
const HDRSIZE = 9, totallen = arr.byteLength,
checkChar = (o, symb) => { return String.fromCharCode(arr.getUint8(o)) === symb; },
getCode = o => arr.getUint8(o)
const HDRSIZE = 9, totallen = arr.byteLength;

let curr = src_shift || 0, fullres = 0, tgtbuf = null;

Expand All @@ -1997,7 +1995,9 @@ async function R__unzip(arr, tgtsize, noalert, src_shift) {
return Promise.resolve(null);
}

const checkFmt = (a, b, c) => { return checkChar(curr, a) && checkChar(curr + 1, b) && (getCode(curr + 2) === c); };
const getCode = o => arr.getUint8(o),
checkChar = (o, symb) => { return getCode(o) === symb.charCodeAt(0); },
checkFmt = (a, b, c) => { return checkChar(curr, a) && checkChar(curr + 1, b) && (getCode(curr + 2) === c); };

if (checkFmt('Z', 'L', 8)) {
fmt = 'new';
Expand All @@ -2008,7 +2008,7 @@ async function R__unzip(arr, tgtsize, noalert, src_shift) {
fmt = 'LZMA';
else if (checkFmt('Z', 'S', 1))
fmt = 'ZSTD';
else if (checkChar(curr, 'L') && checkChar(curr+1, '4')) {
else if (checkChar(curr, 'L') && checkChar(curr + 1, '4')) {
fmt = 'LZ4'; CHKSUM = 8;
}

Expand Down

0 comments on commit 75c24e0

Please sign in to comment.