Skip to content

Commit e19c37d

Browse files
committed
handle packet len too large
1 parent 0ad688a commit e19c37d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

ccsds-lib/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub enum Error {
66
#[error(transparent)]
77
Io(#[from] std::io::Error),
88

9+
#[error("Packet length greater than maximum {0}: {1}")]
10+
InvalidPacketLen(usize, usize),
11+
912
#[error("Invalid timecode config: {0}")]
1013
TimecodeConfig(String),
1114

ccsds-lib/src/spacepacket/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ impl Packet {
159159
let ph = PrimaryHeader::decode(&buf[..PrimaryHeader::LEN])?;
160160
let data_len = ph.len_minus1 as usize + 1;
161161
let total_len = PrimaryHeader::LEN + data_len;
162+
if total_len > buf.len() {
163+
return Err(Error::InvalidPacketLen(Packet::MAX_LEN, total_len));
164+
}
162165
file.read_exact(&mut buf[PrimaryHeader::LEN..total_len])?;
163166

164167
Ok(Packet {

0 commit comments

Comments
 (0)