forge
Explore
Log in

Don't you dare go Hollow

B14: dvbsub replace be16().unwrap() with ? (Corrupt)

Browse files at this commit

2fd03db708e6d740ebcedc973a67cb595c9d8528Ahmet Kaan GümüşParent: 22f0f3f
Guards already bound every index, so no input panicked today; the unwraps
are now Corrupt errors instead of panic paths. No output change.
crates/ec-dvbsub/src/lib.rsmodified+6 -6
@@ -351,8 +351,8 @@ impl DvbSubDecoder {
351 }351 }
352 let id = b[0];352 let id = b[0];
353 let fill = b[1] & 0x08 != 0;353 let fill = b[1] & 0x08 != 0;
354- let w = be16(b, 2).unwrap() as u32;354+ let w = be16(b, 2).ok_or_else(|| Error::corrupt("dvbsub: short region composition"))? as u32;
355- let h = be16(b, 4).unwrap() as u32;355+ let h = be16(b, 4).ok_or_else(|| Error::corrupt("dvbsub: short region composition"))? as u32;
356 if w == 0 || h == 0 || w > MAX_DIMENSION || h > MAX_DIMENSION {356 if w == 0 || h == 0 || w > MAX_DIMENSION || h > MAX_DIMENSION {
357 return Err(Error::corrupt("dvbsub: region size out of range"));357 return Err(Error::corrupt("dvbsub: region size out of range"));
358 }358 }
@@ -375,10 +375,10 @@ impl DvbSubDecoder {
375 let mut objects = Vec::new();375 let mut objects = Vec::new();
376 let mut at = 10;376 let mut at = 10;
377 while at + 6 <= b.len() {377 while at + 6 <= b.len() {
378- let oid = be16(b, at).unwrap() as u16;378+ let oid = be16(b, at).ok_or_else(|| Error::corrupt("dvbsub: short region object"))? as u16;
379 let kind = b[at + 2] >> 6;379 let kind = b[at + 2] >> 6;
380- let x = (be16(b, at + 2).unwrap() & 0xFFF) as u32;380+ let x = (be16(b, at + 2).ok_or_else(|| Error::corrupt("dvbsub: short region object"))? & 0xFFF) as u32;
381- let y = (be16(b, at + 4).unwrap() & 0xFFF) as u32;381+ let y = (be16(b, at + 4).ok_or_else(|| Error::corrupt("dvbsub: short region object"))? & 0xFFF) as u32;
382 objects.push((oid, x, y));382 objects.push((oid, x, y));
383 at += if kind == 1 || kind == 2 { 8 } else { 6 };383 at += if kind == 1 || kind == 2 { 8 } else { 6 };
384 }384 }
@@ -435,7 +435,7 @@ impl DvbSubDecoder {
435 if b.len() < 3 {435 if b.len() < 3 {
436 return Err(Error::corrupt("dvbsub: short object"));436 return Err(Error::corrupt("dvbsub: short object"));
437 }437 }
438- let oid = be16(b, 0).unwrap() as u16;438+ let oid = be16(b, 0).ok_or_else(|| Error::corrupt("dvbsub: short object"))? as u16;
439 let method = (b[2] >> 2) & 3;439 let method = (b[2] >> 2) & 3;
440 if method != 0 {440 if method != 0 {
441 return Ok(()); // character-coded objects are not bitmaps441 return Ok(()); // character-coded objects are not bitmaps