Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Twcc wraparound uint16 promotion case #2101

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sirknightj
Copy link
Contributor

@sirknightj sirknightj commented Feb 6, 2025

Issue #, if available:

What was changed?

  • PeerConnection.c: Added type casting to prevent integer promotion issues when handling sequence number wraparound in the twccRollingWindowDeletion function.
  • Rtcp.c: Added type casting to prevent integer promotion issues when handling sequence number wraparound in the updateTwccHashTable function.
  • RtcpFunctionalityTest.cpp: Added a new test case to validate the behavior of sequence number handling when integer promotion occurs due to UINT16_MAX.

Why was it changed?

  • Integer promotion issue was identified in the handling of sequence numbers during RTP processing by the user of the linked issue. Specifically, when the lastReportedSeqNum is exactly UINT16_MAX, the subsequent increment can cause incorrect behavior due to promotion to a larger integer type.
  • This fix ensures that sequence number comparisons are performed correctly, even when the lastReportedSeqNum is at the value of UINT16_MAX.

How was it changed?

  • In PeerConnection.c and Rtcp.c, explicit casting to UINT16 was added to the sequence number comparisons to prevent unintentional integer promotion to a larger type.
  • Note: Although the expression (lastReportedSeqNum + 1) can be promoted to a larger integer type, the explicit casting ensures that the result remains within the bounds of UINT16, effectively voiding the promotion.
  • In RtcpFunctionalityTest.cpp, a new test was added to simulate the case where lastReportedSeqNum is UINT16_MAX and ensure that the integer promotion does not cause any issues when updating the hash table.

What testing was done for the changes?

  • A new unit test, updateTwccHashTableIntPromotionCase, was created to verify that the system correctly handles the sequence number wraparound and integer promotion scenario. This test checks the proper clearing of the hash table when sequence numbers wrap around from UINT16_MAX. On my Macbook Pro, the newly added test gets stuck in an infinite loop without the fix. After the fix, the new test exits the loop cleanly.
  • Existing functionality was validated to ensure that no regressions were introduced.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sirknightj sirknightj added v1.13.0 bug Something isn't working and removed bug Something isn't working labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v1.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants