Skip to content

Fixes to use the same buffer as input and output #320

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

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

sirzooro
Copy link
Contributor

@sirzooro sirzooro commented Jun 7, 2025

Added checks for the same buffer to stop copying data when not needed. Also fixed srtpCipherAesCmHmacSha1 to work with one buffer when encrypting and decrypting RTCP packets.

Copy link

codecov bot commented Jun 7, 2025

Codecov Report

Attention: Patch coverage is 94.18605% with 5 lines in your changes missing coverage. Please review.

Project coverage is 80.62%. Comparing base (cb54932) to head (a50d986).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
srtp_cipher_aes_cm_hmac_sha1.go 90.56% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #320      +/-   ##
==========================================
+ Coverage   80.56%   80.62%   +0.06%     
==========================================
  Files          18       18              
  Lines        1662     1683      +21     
==========================================
+ Hits         1339     1357      +18     
- Misses        221      223       +2     
- Partials      102      103       +1     
Flag Coverage Δ
go 80.62% <94.18%> (+0.06%) ⬆️
wasm 80.27% <94.18%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Added checks for the same buffer to stop copying data when not needed.
Also fixed srtpCipherAesCmHmacSha1 to work with one buffer when
encrypting and decrypting RTCP packets.
@sirzooro sirzooro force-pushed the same_buffer_fixes branch from 4227879 to a50d986 Compare June 7, 2025 12:41
@sirzooro sirzooro requested review from JoeTurki and at-wat June 7, 2025 12:47
Copy link
Member

@at-wat at-wat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -59,9 +63,7 @@ func (c *Context) decryptRTCP(dst, encrypted []byte) ([]byte, error) {
}
}

out := allocateIfMismatch(dst, encrypted)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: allocateIfMismatch handled nil dst but growBuffer in cipher.decryptRTCP also handles nil output buffer

sameBuffer := isSameBuffer(dst, encrypted)

if !sameBuffer {
copy(dst, encrypted[:srtcpHeaderSize]) // Copy the first 8 bytes (RTCP header)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the original code didn't do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocateIfMismatch seems to have copied the buffer.
Fixed code is nice👍

@sirzooro sirzooro merged commit 30d3f14 into pion:master Jun 12, 2025
14 checks passed
@sirzooro sirzooro deleted the same_buffer_fixes branch June 12, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants