Skip to content

Commit 93eed01

Browse files
committed
Fix - correctly handle LZ4 uncompression
LZ4 places extra 8 bytes for checksum (ignored in JSROOT). But when original buffer bigger than 16MB, several independent compressed buffers created. With LZ4 compression this does not worked
1 parent 0bf78b5 commit 93eed01

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scripts/JSRootIOEvolution.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@
156156
JSROOT.R__unzip = function(arr, tgtsize, noalert, src_shift) {
157157
// Reads header envelope, determines zipped size and unzip content
158158

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;
160160

161161
function getChar(o) { return String.fromCharCode(arr.getUint8(o)); }
162162

163163
function getCode(o) { return arr.getUint8(o); }
164164

165165
while (fullres < tgtsize) {
166166

167-
var fmt = "unknown", off = 0, HDRSIZE = 9;
167+
var fmt = "unknown", off = 0, CHKSUM = 0;
168168

169169
if (curr + HDRSIZE >= totallen) {
170170
if (!noalert) JSROOT.alert("Error R__unzip: header size exceeds buffer size");
@@ -174,7 +174,7 @@
174174
if (getChar(curr) == 'Z' && getChar(curr+1) == 'L' && getCode(curr+2) == 8) { fmt = "new"; off = 2; } else
175175
if (getChar(curr) == 'C' && getChar(curr+1) == 'S' && getCode(curr+2) == 8) { fmt = "old"; off = 0; } else
176176
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; }
178178

179179
/*
180180
if (fmt == "LZMA") {
@@ -214,7 +214,7 @@
214214

215215
var srcsize = HDRSIZE + ((getCode(curr+3) & 0xff) | ((getCode(curr+4) & 0xff) << 8) | ((getCode(curr+5) & 0xff) << 16));
216216

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));
218218

219219
// place for unpacking
220220
if (!tgtbuf) tgtbuf = new ArrayBuffer(tgtsize);

0 commit comments

Comments
 (0)