Skip to content

Commit edd5ca2

Browse files
committed
fix: sysex7 packet with invalid size passes validation
1 parent 3f47e53 commit edd5ca2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

midi2/src/sysex7/packet.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ impl<'a> core::convert::TryFrom<&'a [u32]> for Packet {
3131
));
3232
}
3333

34+
if u8::from(data[0].nibble(3)) > 6 {
35+
return Err(error::InvalidData(sysex7::ERR_INVALID_PACKET_SIZE));
36+
}
37+
3438
status_from_data(data)?;
3539

3640
Ok(Packet({
@@ -129,6 +133,14 @@ mod tests {
129133
);
130134
}
131135

136+
#[test]
137+
fn construction_invalid_payload_size() {
138+
assert_eq!(
139+
Packet::try_from(&[0x3007_0000, 0x0, 0x0, 0x0][..]),
140+
Err(error::InvalidData(sysex7::ERR_INVALID_PACKET_SIZE)),
141+
);
142+
}
143+
132144
#[test]
133145
fn construction_complete() {
134146
assert_eq!(

0 commit comments

Comments
 (0)