Skip to content

Commit

Permalink
[SCTP] pull sctp_proto bug fix related to self.next_ssn +=1
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 16, 2024
1 parent 69d0367 commit e1e567b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
45 changes: 45 additions & 0 deletions rtc-sctp/src/queue/queue_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,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(())
}
6 changes: 3 additions & 3 deletions rtc-sctp/src/queue/reassembly_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl ReassemblyQueue {
self.unordered.remove(0)
} else {
if ordered_chunks.ssn == self.next_ssn {
self.next_ssn += 1;
self.next_ssn = self.next_ssn.wrapping_add(1);
}
self.ordered.remove(0)
}
Expand All @@ -369,7 +369,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 @@ -399,7 +399,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 e1e567b

Please sign in to comment.