mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avpacket: fix leak on realloc in av_packet_add_side_data()
If realloc fails, the pointer is overwritten and the previously allocated buffer is leaked, which goes against the expected functionality of keeping the packet unchanged in case of error. Signed-off-by: James Almer <jamrial@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net>
This commit is contained in:
parent
c7ab0eb305
commit
aa498c3183
@ -240,16 +240,17 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
|||||||
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
|
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
|
||||||
uint8_t *data, size_t size)
|
uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
|
AVPacketSideData *tmp;
|
||||||
int elems = pkt->side_data_elems;
|
int elems = pkt->side_data_elems;
|
||||||
|
|
||||||
if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
|
if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
|
||||||
return AVERROR(ERANGE);
|
return AVERROR(ERANGE);
|
||||||
|
|
||||||
pkt->side_data = av_realloc(pkt->side_data,
|
tmp = av_realloc(pkt->side_data, (elems + 1) * sizeof(*tmp));
|
||||||
(elems + 1) * sizeof(*pkt->side_data));
|
if (!tmp)
|
||||||
if (!pkt->side_data)
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
pkt->side_data = tmp;
|
||||||
pkt->side_data[elems].data = data;
|
pkt->side_data[elems].data = data;
|
||||||
pkt->side_data[elems].size = size;
|
pkt->side_data[elems].size = size;
|
||||||
pkt->side_data[elems].type = type;
|
pkt->side_data[elems].type = type;
|
||||||
|
Loading…
Reference in New Issue
Block a user