Skip to content

Commit

Permalink
Merge pull request #9 from xnorpx/xnorpx/8
Browse files Browse the repository at this point in the history
Wrap around ssn to 0 and avoid panic
  • Loading branch information
rainliu authored Mar 16, 2024
2 parents d154eb0 + 9e85fbd commit 3d04475
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/queue/queue_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,3 +991,48 @@ 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(())
}

#[test]
fn test_reassembly_queue_ssn_overflow_in_forward_tsn_for_ordered() -> 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());
}
rq.forward_tsn_for_ordered(u16::MAX);

Ok(())
}
4 changes: 2 additions & 2 deletions 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.wrapping_add(1);
}
self.ordered.remove(0)
} else {
Expand Down Expand Up @@ -363,7 +363,7 @@ impl ReassemblyQueue {

// Finally, forward next_ssn
if sna16lte(self.next_ssn, last_ssn) {
self.next_ssn = last_ssn + 1;
self.next_ssn = last_ssn.wrapping_add(1);
}
}

Expand Down

0 comments on commit 3d04475

Please sign in to comment.