mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
encoder: add error checking to videoFrameSize
av_image_get_buffer_size can return a negative error code. Prevents casting such an error to a large positive integer that may cause a bad_alloc exception on the subsequent buffer allocation. Change-Id: Ie8a7987dcf16957a21496e791c34957bb2e35bfc
This commit is contained in:
@ -34,7 +34,7 @@ namespace ring {
|
||||
|
||||
//=== HELPERS ==================================================================
|
||||
|
||||
std::size_t
|
||||
int
|
||||
videoFrameSize(int format, int width, int height)
|
||||
{
|
||||
return av_image_get_buffer_size((AVPixelFormat)format, width, height, 1);
|
||||
|
@ -42,7 +42,7 @@ using AudioFrame = DRing::AudioFrame;
|
||||
using VideoFrame = DRing::VideoFrame;
|
||||
|
||||
// Some helpers
|
||||
std::size_t videoFrameSize(int format, int width, int height);
|
||||
int videoFrameSize(int format, int width, int height);
|
||||
|
||||
#endif // RING_VIDEO
|
||||
|
||||
|
@ -286,7 +286,9 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
|
||||
const int height = encoderCtx->height;
|
||||
const int format = encoderCtx->pix_fmt;
|
||||
scaledFrameBufferSize_ = videoFrameSize(format, width, height);
|
||||
if (scaledFrameBufferSize_ <= AV_INPUT_BUFFER_MIN_SIZE)
|
||||
if (scaledFrameBufferSize_ < 0)
|
||||
throw MediaEncoderException(("Could not compute buffer size: " + libav_utils::getError(scaledFrameBufferSize_)).c_str());
|
||||
else if (scaledFrameBufferSize_ <= AV_INPUT_BUFFER_MIN_SIZE)
|
||||
throw MediaEncoderException("buffer too small");
|
||||
|
||||
scaledFrameBuffer_.reserve(scaledFrameBufferSize_);
|
||||
|
Reference in New Issue
Block a user