forge
Explore
Log in

Don't you dare go Hollow

B3: ec-h264 length-prefixed packets: push slices without to_vec, reject trailing bytes shorter than the NAL length field as Corrupt

Browse files at this commit

8e80cd770af467900644cfec454e24f1c88e0085Ahmet Kaan GümüşParent: 22f0f3f
Evidence: trailing 1-3 bytes after the last NAL unit were silently ignored. Not verified against ffmpeg for this exact case. Well-formed streams are unaffected; the to_vec removal does not change bytes.
crates/ec-h264/src/codec.rsmodified+7 -4
@@ -105,8 +105,7 @@ impl H264Decoder {
105105 fn decode_packet_payload(&mut self, data: &[u8]) -> Result<()> {
106106 let Some(size) = self.nal_length_size else {
107107 for unit in AnnexBIter::new(data) {
108- let unit = unit.to_vec();
109- self.push(&unit)?;
108+ self.push(unit)?;
110109 }
111110 return Ok(());
112111 };
@@ -125,10 +124,14 @@ impl H264Decoder {
125124 "H.264: a NAL unit of {length} bytes overruns the packet"
126125 ))
127126 })?;
128- let unit = data[offset..end].to_vec();
129- self.push(&unit)?;
127+ self.push(&data[offset..end])?;
130128 offset = end;
131129 }
130+ if offset != data.len() {
131+ return Err(Error::corrupt(
132+ "H.264: trailing bytes too short for a NAL length field",
133+ ));
134+ }
132135 Ok(())
133136 }
134137