Skip to content

Commit 0f2db13

Browse files
authored
fix panics when parsing rtcp packets with invalid block sizes (#678)
1 parent a7d2f8f commit 0f2db13

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

rtcp/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub enum Error {
9696
BadStructMemberType,
9797
#[error("Cannot read into non-pointer")]
9898
BadReadParameter,
99+
#[error("Invalid block size")]
100+
InvalidBlockSize,
99101

100102
#[error("{0}")]
101103
Util(#[from] util::Error),

rtcp/src/extended_report/dlrr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ impl Unmarshal for DLRRReportBlock {
123123
}
124124

125125
let xr_header = XRHeader::unmarshal(raw_packet)?;
126-
let block_length = xr_header.block_length * 4;
126+
let block_length = match xr_header.block_length.checked_mul(4) {
127+
Some(length) => length,
128+
None => return Err(error::Error::InvalidBlockSize.into()),
129+
};
127130
if block_length % DLRR_REPORT_LENGTH != 0 || raw_packet.remaining() < block_length as usize
128131
{
129132
return Err(error::Error::PacketTooShort.into());

rtcp/src/extended_report/prt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ impl Unmarshal for PacketReceiptTimesReportBlock {
118118
}
119119

120120
let xr_header = XRHeader::unmarshal(raw_packet)?;
121-
let block_length = xr_header.block_length * 4;
121+
let block_length = match xr_header.block_length.checked_mul(4) {
122+
Some(length) => length,
123+
None => return Err(error::Error::InvalidBlockSize.into()),
124+
};
122125
if block_length < PRT_REPORT_BLOCK_MIN_LENGTH
123126
|| (block_length - PRT_REPORT_BLOCK_MIN_LENGTH) % 4 != 0
124127
|| raw_packet.remaining() < block_length as usize

rtcp/src/extended_report/rle.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ impl Unmarshal for RLEReportBlock {
210210
}
211211

212212
let xr_header = XRHeader::unmarshal(raw_packet)?;
213-
let block_length = xr_header.block_length * 4;
213+
let block_length = match xr_header.block_length.checked_mul(4) {
214+
Some(length) => length,
215+
None => return Err(error::Error::InvalidBlockSize.into()),
216+
};
214217
if block_length < RLE_REPORT_BLOCK_MIN_LENGTH
215218
|| (block_length - RLE_REPORT_BLOCK_MIN_LENGTH) % 2 != 0
216219
|| raw_packet.remaining() < block_length as usize

rtcp/src/extended_report/rrt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ impl Unmarshal for ReceiverReferenceTimeReportBlock {
9898
}
9999

100100
let xr_header = XRHeader::unmarshal(raw_packet)?;
101-
let block_length = xr_header.block_length * 4;
101+
let block_length = match xr_header.block_length.checked_mul(4) {
102+
Some(length) => length,
103+
None => return Err(error::Error::InvalidBlockSize.into()),
104+
};
102105
if block_length != RRT_REPORT_BLOCK_LENGTH || raw_packet.remaining() < block_length as usize
103106
{
104107
return Err(error::Error::PacketTooShort.into());

rtcp/src/extended_report/ssr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ impl Unmarshal for StatisticsSummaryReportBlock {
186186
}
187187

188188
let xr_header = XRHeader::unmarshal(raw_packet)?;
189-
let block_length = xr_header.block_length * 4;
189+
let block_length = match xr_header.block_length.checked_mul(4) {
190+
Some(length) => length,
191+
None => return Err(error::Error::InvalidBlockSize.into()),
192+
};
190193
if block_length != SSR_REPORT_BLOCK_LENGTH || raw_packet.remaining() < block_length as usize
191194
{
192195
return Err(error::Error::PacketTooShort.into());

rtcp/src/extended_report/unknown.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ impl Unmarshal for UnknownReportBlock {
8383
}
8484

8585
let xr_header = XRHeader::unmarshal(raw_packet)?;
86-
let block_length = xr_header.block_length * 4;
86+
let block_length = match xr_header.block_length.checked_mul(4) {
87+
Some(length) => length,
88+
None => return Err(error::Error::InvalidBlockSize.into()),
89+
};
8790
if raw_packet.remaining() < block_length as usize {
8891
return Err(error::Error::PacketTooShort.into());
8992
}

rtcp/src/extended_report/vm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ impl Unmarshal for VoIPMetricsReportBlock {
149149
}
150150

151151
let xr_header = XRHeader::unmarshal(raw_packet)?;
152-
let block_length = xr_header.block_length * 4;
152+
let block_length = match xr_header.block_length.checked_mul(4) {
153+
Some(length) => length,
154+
None => return Err(error::Error::InvalidBlockSize.into()),
155+
};
153156
if block_length != VM_REPORT_BLOCK_LENGTH || raw_packet.remaining() < block_length as usize
154157
{
155158
return Err(error::Error::PacketTooShort.into());

0 commit comments

Comments
 (0)