Skip to content

Commit 69d76be

Browse files
committed
Check decoded segment size to avoid failures
1 parent 26d0d94 commit 69d76be

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

modules/io.mjs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,9 +3055,16 @@ class TFile {
30553055
}
30563056
}
30573057
if (!res) {
3058-
return { place, blobs: [], addBuffer: function(indx, buf, o) {
3059-
this.blobs[indx/2] = new DataView(buf, o, this.place[indx + 1]);
3060-
}}
3058+
return {
3059+
place,
3060+
blobs: [],
3061+
expectedSize: function(indx) {
3062+
return this.place[indx + 1];
3063+
},
3064+
addBuffer: function(indx, buf, o) {
3065+
this.blobs[indx/2] = new DataView(buf, o, this.place[indx + 1]);
3066+
}
3067+
};
30613068
}
30623069

30633070
res = { place, reorder: [], place_new: [], blobs: [] };
@@ -3081,6 +3088,10 @@ class TFile {
30813088

30823089
res.reorder.forEach(elem => res.place_new.push(elem.pos, elem.len));
30833090

3091+
res.expectedSize = function(indx) {
3092+
return this.reorder[indx / 2].len;
3093+
};
3094+
30843095
res.addBuffer = function(indx, buf, o) {
30853096
const elem = this.reorder[indx / 2],
30863097
pos0 = elem.pos;
@@ -3342,14 +3353,16 @@ class TFile {
33423353
o++;
33433354
}
33443355

3345-
if (!finish_header || (segm_start > segm_last)) {
3356+
const segm_size = segm_last - segm_start + 1;
3357+
3358+
if (!finish_header || (segm_size <= 0) || (reorder.expectedSize(n) !== segm_size)) {
33463359
console.error('Failure decoding multirange header - fallback to single range request');
33473360
return send_new_request('noranges');
33483361
}
33493362

33503363
reorder.addBuffer(n, res, o);
33513364

3352-
o += (segm_last - segm_start + 1);
3365+
o += segm_size;
33533366
}
33543367

33553368
send_new_request(true);

0 commit comments

Comments
 (0)