Skip to content

Commit 1e675c7

Browse files
DanilChapovalovWebRTC LUCI CQ
authored andcommitted
Zero memory for FEC recovered packets when size increases
rtc::CopyOnWriteBuffer::SetSize extends buffer with uninitialized memory by design. It is up to the user of the rtc::CopyOnWriteBuffer to ensure it is initialized. (cherry picked from commit 4f74385) No-Try: true Bug: chromium:1404299 Change-Id: I41f3f91bf20ff440984d78ed81e01f5db36ff509 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/290400 Commit-Queue: Danil Chapovalov <[email protected]> Reviewed-by: Per Kjellander <[email protected]> Cr-Original-Commit-Position: refs/heads/main@{#38972} Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291541 Cr-Commit-Position: refs/branch-heads/5481@{#4} Cr-Branched-From: 2e1a9a4-refs/heads/main@{#38901}
1 parent 36b2ad3 commit 1e675c7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modules/rtp_rtcp/source/forward_error_correction.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ void ForwardErrorCorrection::GenerateFecPayloads(
225225

226226
size_t fec_packet_length = fec_header_size + media_payload_length;
227227
if (fec_packet_length > fec_packet->data.size()) {
228-
// Recall that XORing with zero (which the FEC packets are prefilled
229-
// with) is the identity operator, thus all prior XORs are
230-
// still correct even though we expand the packet length here.
228+
size_t old_size = fec_packet->data.size();
231229
fec_packet->data.SetSize(fec_packet_length);
230+
memset(fec_packet->data.MutableData() + old_size, 0,
231+
fec_packet_length - old_size);
232232
}
233233
XorHeaders(*media_packet, fec_packet);
234234
XorPayloads(*media_packet, media_payload_length, fec_header_size,
@@ -619,7 +619,10 @@ void ForwardErrorCorrection::XorPayloads(const Packet& src,
619619
RTC_DCHECK_LE(kRtpHeaderSize + payload_length, src.data.size());
620620
RTC_DCHECK_LE(dst_offset + payload_length, dst->data.capacity());
621621
if (dst_offset + payload_length > dst->data.size()) {
622-
dst->data.SetSize(dst_offset + payload_length);
622+
size_t old_size = dst->data.size();
623+
size_t new_size = dst_offset + payload_length;
624+
dst->data.SetSize(new_size);
625+
memset(dst->data.MutableData() + old_size, 0, new_size - old_size);
623626
}
624627
uint8_t* dst_data = dst->data.MutableData();
625628
const uint8_t* src_data = src.data.cdata();

0 commit comments

Comments
 (0)