Skip to content

Commit 1630412

Browse files
authored
Merge pull request #81 from image-rs/fix-burst-derive-overflow
Fix: overflow into low codes in burst derive
2 parents 3d3f4e3 + d3dd943 commit 1630412

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/decode.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ impl Table {
15691569
}
15701570

15711571
fn derive(&mut self, from: &DerivationBase, byte: u8) {
1572+
debug_assert!(self.len < MAX_ENTRIES);
15721573
let idx = self.len & MASK;
15731574

15741575
let parent = usize::from(from.code) & MASK;
@@ -1591,7 +1592,13 @@ impl Table {
15911592
}
15921593

15931594
fn derive_burst(&mut self, from: &mut DerivationBase, burst: &[Code], first: &[u8]) {
1594-
for (&code, &first_byte) in burst.iter().zip(first.iter()) {
1595+
// A burst is constrained to the number of possible codes before a size switch, however at
1596+
// the maximum possible size we *never* perform a switch again (until reset) and so the
1597+
// size of the burst is not constrained. But we must not derive any of those additional
1598+
// codes which would wrap into the start and overwrite entries for codes 0-5.
1599+
let max = MAX_ENTRIES - self.len;
1600+
1601+
for (&code, &first_byte) in burst.iter().zip(first.iter()).take(max) {
15951602
self.derive(from, first_byte);
15961603
from.code = code;
15971604
from.first = first_byte;

0 commit comments

Comments
 (0)