Skip to content
Snippets Groups Projects
Commit 2f56a0d5 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

audiortp: prevent out of bounds read

Add zero padding to pcm buffers (if needed) before encoding them to avoid
out of bounds memory access.

Refs #49181

Change-Id: I804aef3e1acf08301dde388780f4502e51bf57f2
parent 4aba7c36
No related branches found
No related tags found
No related merge requests found
...@@ -343,6 +343,16 @@ size_t AudioRtpStream::processDataEncode() ...@@ -343,6 +343,16 @@ size_t AudioRtpStream::processDataEncode()
ERROR("Audio codec already destroyed"); ERROR("Audio codec already destroyed");
return 0; return 0;
} }
const auto frameSize = out->frames();
const auto codecFrameSize = codec->getFrameSize();
if (codecFrameSize > frameSize) {
// PCM too small (underflow), add zero padding to avoid reading past
// end of buffer when encoding, for every channel
for (auto &c : out->getData())
c.resize(codecFrameSize, 0);
}
size_t encoded = codec->encode(out->getData(), encodedData_.data(), encodedData_.size()); size_t encoded = codec->encode(out->getData(), encodedData_.data(), encodedData_.size());
return encoded; return encoded;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment