Skip to content

Commit

Permalink
Wrap around ssn to 0 and avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
xnorpx committed Mar 15, 2024
1 parent d154eb0 commit e4c7e19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/queue/queue_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,3 +991,26 @@ fn test_chunk_set_incomplete_chunk_set_no_contiguous_tsn() -> Result<()> {
);
Ok(())
}

#[test]
fn test_reassembly_queue_ssn_overflow() -> Result<()> {
let mut rq = ReassemblyQueue::new(0);

let org_ppi = PayloadProtocolIdentifier::Binary;

for stream_sequence_number in 0..=u16::MAX {
let chunk = ChunkPayloadData {
payload_type: org_ppi,
beginning_fragment: true,
ending_fragment: true,
tsn: 10,
stream_sequence_number,
user_data: Bytes::from_static(b"123"),
..Default::default()
};
assert!(rq.push(chunk));
assert!(rq.read().is_some());
}

Ok(())
}
2 changes: 1 addition & 1 deletion src/queue/reassembly_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl ReassemblyQueue {
return None;
}
if chunks.ssn == self.next_ssn {
self.next_ssn += 1;
self.next_ssn = self.next_ssn.saturating_add(1);
}
self.ordered.remove(0)
} else {
Expand Down

0 comments on commit e4c7e19

Please sign in to comment.