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 commit8e80cd770af467900644cfec454e24f1c88e0085Parent: 22f0f3f1 changed file +7 -4
crates/ec-h264/src/codec.rsmodified+7 -4
| @@ -105,8 +105,7 @@ impl H264Decoder { | |||
| 105 | fn decode_packet_payload(&mut self, data: &[u8]) -> Result<()> { | 105 | fn decode_packet_payload(&mut self, data: &[u8]) -> Result<()> { |
| 106 | let Some(size) = self.nal_length_size else { | 106 | let Some(size) = self.nal_length_size else { |
| 107 | for unit in AnnexBIter::new(data) { | 107 | for unit in AnnexBIter::new(data) { |
| 108 | - let unit = unit.to_vec(); | 108 | + self.push(unit)?; |
| 109 | - self.push(&unit)?; | ||
| 110 | } | 109 | } |
| 111 | return Ok(()); | 110 | return Ok(()); |
| 112 | }; | 111 | }; |
| @@ -125,10 +124,14 @@ impl H264Decoder { | |||
| 125 | "H.264: a NAL unit of {length} bytes overruns the packet" | 124 | "H.264: a NAL unit of {length} bytes overruns the packet" |
| 126 | )) | 125 | )) |
| 127 | })?; | 126 | })?; |
| 128 | - let unit = data[offset..end].to_vec(); | 127 | + self.push(&data[offset..end])?; |
| 129 | - self.push(&unit)?; | ||
| 130 | offset = end; | 128 | offset = end; |
| 131 | } | 129 | } |
| 130 | + if offset != data.len() { | ||
| 131 | + return Err(Error::corrupt( | ||
| 132 | + "H.264: trailing bytes too short for a NAL length field", | ||
| 133 | + )); | ||
| 134 | + } | ||
| 132 | Ok(()) | 135 | Ok(()) |
| 133 | } | 136 | } |
| 134 | 137 | ||