Skip to content

Commit

Permalink
remove debug assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Mar 6, 2017
1 parent 80ba6f0 commit eae867c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ pub fn aac_audio_packet(input: &[u8], size: usize) -> IResult<&[u8], AACAudioPac
return IResult::Incomplete(Needed::Size(size));
}

if size < 1 {
return IResult::Incomplete(Needed::Size(1));
}

let (remaining, packet_type) = try_parse!(input, switch!(be_u8,
0 => value!(AACPacketType::SequenceHeader) |
1 => value!(AACPacketType::Raw)
)
);

assert_eq!(size - 1, remaining.len());

IResult::Done(&input[size..], AACAudioPacket {
packet_type: packet_type,
aac_data: &input[1..size]
Expand All @@ -223,6 +225,10 @@ pub fn audio_data(input: &[u8], size: usize) -> IResult<&[u8], AudioData> {
return IResult::Incomplete(Needed::Size(size));
}

if size < 1 {
return IResult::Incomplete(Needed::Size(1));
}

let (remaining, (sformat, srate, ssize, stype)) = try_parse!(input, bits!(
tuple!(
switch!(take_bits!(u8, 4),
Expand Down Expand Up @@ -257,8 +263,6 @@ pub fn audio_data(input: &[u8], size: usize) -> IResult<&[u8], AudioData> {
)
));

assert_eq!(size - 1, remaining.len());

IResult::Done(&input[size..], AudioData {
sound_format: sformat,
sound_rate: srate,
Expand Down Expand Up @@ -315,8 +319,6 @@ pub fn audio_data_header(input: &[u8]) -> IResult<&[u8], AudioDataHeader> {
)
));

assert_eq!(input.len() - 1, remaining.len());

IResult::Done(remaining, AudioDataHeader {
sound_format: sformat,
sound_rate: srate,
Expand Down Expand Up @@ -389,6 +391,10 @@ pub fn avc_video_packet(input: &[u8], size: usize) -> IResult<&[u8], AVCVideoPac
return IResult::Incomplete(Needed::Size(size));
}

if size < 4 {
return IResult::Incomplete(Needed::Size(4));
}

let (remaining, (packet_type, composition_time)) = try_parse!(input, tuple!(
switch!(be_u8,
0 => value!(AVCPacketType::SequenceHeader) |
Expand All @@ -398,8 +404,6 @@ pub fn avc_video_packet(input: &[u8], size: usize) -> IResult<&[u8], AVCVideoPac
be_i24
));

assert_eq!(size - 4, remaining.len());

IResult::Done(&input[size..], AVCVideoPacket {
packet_type: packet_type,
composition_time: composition_time,
Expand All @@ -419,6 +423,10 @@ pub fn video_data(input: &[u8], size: usize) -> IResult<&[u8], VideoData> {
return IResult::Incomplete(Needed::Size(size));
}

if size < 1 {
return IResult::Incomplete(Needed::Size(1));
}

let (remaining, (frame_type, codec_id)) = try_parse!(input, bits!(
tuple!(
switch!(take_bits!(u8, 4),
Expand All @@ -442,8 +450,6 @@ pub fn video_data(input: &[u8], size: usize) -> IResult<&[u8], VideoData> {
)
));

assert_eq!(size - 1, remaining.len());

IResult::Done(&input[size..], VideoData {
frame_type: frame_type,
codec_id: codec_id,
Expand Down Expand Up @@ -485,8 +491,6 @@ pub fn video_data_header(input: &[u8]) -> IResult<&[u8], VideoDataHeader> {
)
));

assert_eq!(input.len() - 1, remaining.len());

IResult::Done(remaining, VideoDataHeader {
frame_type: frame_type,
codec_id: codec_id,
Expand Down

0 comments on commit eae867c

Please sign in to comment.