Fix several UBsan issues with memcpy
Most of the changes are trivial. Bug: webrtc:14432 Change-Id: I0444527bf57c72c8d65f69754b4a4a1c1d7b2e92 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275340 Reviewed-by: Erik Språng <sprang@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Victor Boivie <boivie@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38074}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
a0adeb7059
commit
8c725f368c
@ -91,7 +91,9 @@ bool App::Create(uint8_t* packet,
|
||||
|
||||
ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], sender_ssrc());
|
||||
ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_);
|
||||
if (!data_.empty()) {
|
||||
memcpy(&packet[*index + 8], data_.data(), data_.size());
|
||||
}
|
||||
*index += (8 + data_.size());
|
||||
RTC_DCHECK_EQ(index_end, *index);
|
||||
return true;
|
||||
|
||||
@ -672,8 +672,12 @@ bool RtpPacket::RemoveExtension(ExtensionType type) {
|
||||
}
|
||||
|
||||
// Copy payload data to new packet.
|
||||
if (payload_size() > 0) {
|
||||
memcpy(new_packet.AllocatePayload(payload_size()), payload().data(),
|
||||
payload_size());
|
||||
} else {
|
||||
new_packet.SetPayloadSize(0);
|
||||
}
|
||||
|
||||
// Allocate padding -- must be last!
|
||||
new_packet.SetPadding(padding_size());
|
||||
|
||||
@ -383,7 +383,9 @@ bool RtpPacketizerAv1::NextPacket(RtpPacketToSend* packet) {
|
||||
int payload_offset =
|
||||
std::max(0, obu_offset - (ObuHasExtension(obu.header) ? 2 : 1));
|
||||
size_t payload_size = obu.payload.size() - payload_offset;
|
||||
if (!obu.payload.empty() && payload_size > 0) {
|
||||
memcpy(write_at, obu.payload.data() + payload_offset, payload_size);
|
||||
}
|
||||
write_at += payload_size;
|
||||
// All obus are stored from the beginning, except, may be, the first one.
|
||||
obu_offset = 0;
|
||||
|
||||
@ -694,7 +694,9 @@ std::unique_ptr<RtpPacketToSend> RTPSender::BuildRtxPacket(
|
||||
|
||||
// Add original payload data.
|
||||
auto payload = packet.payload();
|
||||
if (!payload.empty()) {
|
||||
memcpy(rtx_payload + kRtxHeaderSize, payload.data(), payload.size());
|
||||
}
|
||||
|
||||
// Add original additional data.
|
||||
rtx_packet->set_additional_data(packet.additional_data());
|
||||
|
||||
@ -88,8 +88,11 @@ class BoundedByteWriter {
|
||||
}
|
||||
|
||||
void CopyToVariableData(rtc::ArrayView<const uint8_t> source) {
|
||||
memcpy(data_.data() + FixedSize, source.data(),
|
||||
std::min(source.size(), data_.size() - FixedSize));
|
||||
size_t copy_size = std::min(source.size(), data_.size() - FixedSize);
|
||||
if (source.data() == nullptr || copy_size == 0) {
|
||||
return;
|
||||
}
|
||||
memcpy(data_.data() + FixedSize, source.data(), copy_size);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -128,7 +128,9 @@ StreamResult MemoryStream::DoReserve(size_t size, int* error) {
|
||||
return SR_SUCCESS;
|
||||
|
||||
if (char* new_buffer = new char[size]) {
|
||||
if (buffer_ != nullptr && data_length_ > 0) {
|
||||
memcpy(new_buffer, buffer_, data_length_);
|
||||
}
|
||||
delete[] buffer_;
|
||||
buffer_ = new_buffer;
|
||||
buffer_length_ = size;
|
||||
|
||||
Reference in New Issue
Block a user