|
156 | 156 | JSROOT.R__unzip = function(arr, tgtsize, noalert, src_shift) { |
157 | 157 | // Reads header envelope, determines zipped size and unzip content |
158 | 158 |
|
159 | | - var totallen = arr.byteLength, curr = src_shift || 0, fullres = 0, tgtbuf = null; |
| 159 | + var totallen = arr.byteLength, curr = src_shift || 0, fullres = 0, tgtbuf = null, HDRSIZE = 9; |
160 | 160 |
|
161 | 161 | function getChar(o) { return String.fromCharCode(arr.getUint8(o)); } |
162 | 162 |
|
163 | 163 | function getCode(o) { return arr.getUint8(o); } |
164 | 164 |
|
165 | 165 | while (fullres < tgtsize) { |
166 | 166 |
|
167 | | - var fmt = "unknown", off = 0, HDRSIZE = 9; |
| 167 | + var fmt = "unknown", off = 0, CHKSUM = 0; |
168 | 168 |
|
169 | 169 | if (curr + HDRSIZE >= totallen) { |
170 | 170 | if (!noalert) JSROOT.alert("Error R__unzip: header size exceeds buffer size"); |
|
174 | 174 | if (getChar(curr) == 'Z' && getChar(curr+1) == 'L' && getCode(curr+2) == 8) { fmt = "new"; off = 2; } else |
175 | 175 | if (getChar(curr) == 'C' && getChar(curr+1) == 'S' && getCode(curr+2) == 8) { fmt = "old"; off = 0; } else |
176 | 176 | if (getChar(curr) == 'X' && getChar(curr+1) == 'Z') fmt = "LZMA"; else |
177 | | - if (getChar(curr) == 'L' && getChar(curr+1) == '4') { fmt = "LZ4"; off = 0; HDRSIZE = 17; } |
| 177 | + if (getChar(curr) == 'L' && getChar(curr+1) == '4') { fmt = "LZ4"; off = 0; CHKSUM = 8; } |
178 | 178 |
|
179 | 179 | /* |
180 | 180 | if (fmt == "LZMA") { |
|
214 | 214 |
|
215 | 215 | var srcsize = HDRSIZE + ((getCode(curr+3) & 0xff) | ((getCode(curr+4) & 0xff) << 8) | ((getCode(curr+5) & 0xff) << 16)); |
216 | 216 |
|
217 | | - var uint8arr = new Uint8Array(arr.buffer, arr.byteOffset + curr + HDRSIZE + off, arr.byteLength - curr - HDRSIZE - off); |
| 217 | + var uint8arr = new Uint8Array(arr.buffer, arr.byteOffset + curr + HDRSIZE + off + CHKSUM, Math.min(arr.byteLength - curr - HDRSIZE - off - CHKSUM, srcsize - HDRSIZE - CHKSUM)); |
218 | 218 |
|
219 | 219 | // place for unpacking |
220 | 220 | if (!tgtbuf) tgtbuf = new ArrayBuffer(tgtsize); |
|
0 commit comments