mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Merge commit '9b8d11a76ae7bca8bbb58abb822138f8b42c776c'
* commit '9b8d11a76ae7bca8bbb58abb822138f8b42c776c': avcodec: Use av_reallocp where suitable Conflicts: libavcodec/bitstream.c libavcodec/eatgv.c libavcodec/flashsv.c libavcodec/libtheoraenc.c libavcodec/libvpxenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
8c677a9f06
@ -108,13 +108,17 @@ static int alloc_table(VLC *vlc, int size, int use_static)
|
|||||||
|
|
||||||
vlc->table_size += size;
|
vlc->table_size += size;
|
||||||
if (vlc->table_size > vlc->table_allocated) {
|
if (vlc->table_size > vlc->table_allocated) {
|
||||||
|
int err;
|
||||||
if (use_static)
|
if (use_static)
|
||||||
abort(); // cannot do anything, init_vlc() is used with too little memory
|
abort(); // cannot do anything, init_vlc() is used with too little memory
|
||||||
vlc->table_allocated += (1 << vlc->bits);
|
vlc->table_allocated += (1 << vlc->bits);
|
||||||
vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2);
|
vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2);
|
||||||
if (!vlc->table)
|
if (!vlc->table) {
|
||||||
|
vlc->table_allocated = 0;
|
||||||
|
vlc->table_size = 0;
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,9 +181,10 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (num_blocks_packed > s->num_blocks_packed) {
|
if (num_blocks_packed > s->num_blocks_packed) {
|
||||||
if (av_reallocp_array(&s->block_codebook, num_blocks_packed, sizeof(*s->block_codebook))) {
|
int err;
|
||||||
|
if ((err = av_reallocp(&s->block_codebook, num_blocks_packed * 16)) < 0) {
|
||||||
s->num_blocks_packed = 0;
|
s->num_blocks_packed = 0;
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
}
|
}
|
||||||
s->num_blocks_packed = num_blocks_packed;
|
s->num_blocks_packed = num_blocks_packed;
|
||||||
}
|
}
|
||||||
|
@ -307,13 +307,13 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
/* the block size could change between frames, make sure the buffer
|
/* the block size could change between frames, make sure the buffer
|
||||||
* is large enough, if not, get a larger one */
|
* is large enough, if not, get a larger one */
|
||||||
if (s->block_size < s->block_width * s->block_height) {
|
if (s->block_size < s->block_width * s->block_height) {
|
||||||
int tmpblock_size = 3 * s->block_width * s->block_height;
|
int tmpblock_size = 3 * s->block_width * s->block_height, err;
|
||||||
|
|
||||||
s->tmpblock = av_realloc(s->tmpblock, tmpblock_size);
|
if ((err = av_reallocp(&s->tmpblock, tmpblock_size)) < 0) {
|
||||||
if (!s->tmpblock) {
|
s->block_size = 0;
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
av_log(avctx, AV_LOG_ERROR,
|
||||||
"Cannot allocate decompression buffer.\n");
|
"Cannot allocate decompression buffer.\n");
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
}
|
}
|
||||||
if (s->ver == 2) {
|
if (s->ver == 2) {
|
||||||
s->deflate_block_size = calc_deflate_block_size(tmpblock_size);
|
s->deflate_block_size = calc_deflate_block_size(tmpblock_size);
|
||||||
@ -322,12 +322,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
"Cannot determine deflate buffer size.\n");
|
"Cannot determine deflate buffer size.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
s->deflate_block = av_realloc(s->deflate_block,
|
if ((err = av_reallocp(&s->deflate_block, s->deflate_block_size)) < 0) {
|
||||||
s->deflate_block_size);
|
s->block_size = 0;
|
||||||
if (!s->deflate_block) {
|
av_log(avctx, AV_LOG_ERROR, "Cannot allocate deflate buffer.\n");
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
return err;
|
||||||
"Cannot allocate deflate buffer.\n");
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,7 +349,9 @@ static int flashsv_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
/* we care for keyframes only in Screen Video v2 */
|
/* we care for keyframes only in Screen Video v2 */
|
||||||
s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
|
s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
|
||||||
if (s->is_keyframe) {
|
if (s->is_keyframe) {
|
||||||
s->keyframedata = av_realloc(s->keyframedata, avpkt->size);
|
int err;
|
||||||
|
if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0)
|
||||||
|
return err;
|
||||||
memcpy(s->keyframedata, avpkt->data, avpkt->size);
|
memcpy(s->keyframedata, avpkt->data, avpkt->size);
|
||||||
}
|
}
|
||||||
if(s->ver == 2 && !s->blocks)
|
if(s->ver == 2 && !s->blocks)
|
||||||
|
@ -236,16 +236,14 @@ static int jpg_decode_data(JPGContext *c, int width, int height,
|
|||||||
int swapuv)
|
int swapuv)
|
||||||
{
|
{
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
uint8_t *tmp;
|
|
||||||
int mb_w, mb_h, mb_x, mb_y, i, j;
|
int mb_w, mb_h, mb_x, mb_y, i, j;
|
||||||
int bx, by;
|
int bx, by;
|
||||||
int unesc_size;
|
int unesc_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
tmp = av_realloc(c->buf, src_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
if ((ret = av_reallocp(&c->buf,
|
||||||
if (!tmp)
|
src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
|
||||||
return AVERROR(ENOMEM);
|
return ret;
|
||||||
c->buf = tmp;
|
|
||||||
jpg_unescape(src, src_size, c->buf, &unesc_size);
|
jpg_unescape(src, src_size, c->buf, &unesc_size);
|
||||||
memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
init_get_bits(&gb, c->buf, unesc_size * 8);
|
init_get_bits(&gb, c->buf, unesc_size * 8);
|
||||||
@ -482,8 +480,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
|
|||||||
uint32_t bits;
|
uint32_t bits;
|
||||||
uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
|
uint32_t cur_size, cursor_w, cursor_h, cursor_stride;
|
||||||
uint32_t cursor_hot_x, cursor_hot_y;
|
uint32_t cursor_hot_x, cursor_hot_y;
|
||||||
int cursor_fmt;
|
int cursor_fmt, err;
|
||||||
uint8_t *tmp;
|
|
||||||
|
|
||||||
cur_size = bytestream2_get_be32(gb);
|
cur_size = bytestream2_get_be32(gb);
|
||||||
cursor_w = bytestream2_get_byte(gb);
|
cursor_w = bytestream2_get_byte(gb);
|
||||||
@ -518,13 +515,11 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
|
|||||||
return AVERROR_PATCHWELCOME;
|
return AVERROR_PATCHWELCOME;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = av_realloc(c->cursor, cursor_stride * cursor_h);
|
if ((err = av_reallocp(&c->cursor, cursor_stride * cursor_h)) < 0) {
|
||||||
if (!tmp) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");
|
av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->cursor = tmp;
|
|
||||||
c->cursor_w = cursor_w;
|
c->cursor_w = cursor_w;
|
||||||
c->cursor_h = cursor_h;
|
c->cursor_h = cursor_h;
|
||||||
c->cursor_hot_x = cursor_hot_x;
|
c->cursor_hot_x = cursor_hot_x;
|
||||||
|
@ -37,13 +37,14 @@ static int alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size,
|
|||||||
{
|
{
|
||||||
uint32_t offset = *poutbuf_size;
|
uint32_t offset = *poutbuf_size;
|
||||||
uint8_t nal_header_size = offset ? 3 : 4;
|
uint8_t nal_header_size = offset ? 3 : 4;
|
||||||
void *tmp;
|
int err;
|
||||||
|
|
||||||
*poutbuf_size += sps_pps_size + in_size + nal_header_size;
|
*poutbuf_size += sps_pps_size + in_size + nal_header_size;
|
||||||
tmp = av_realloc(*poutbuf, *poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
if ((err = av_reallocp(poutbuf,
|
||||||
if (!tmp)
|
*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0) {
|
||||||
return AVERROR(ENOMEM);
|
*poutbuf_size = 0;
|
||||||
*poutbuf = tmp;
|
return err;
|
||||||
|
}
|
||||||
if (sps_pps)
|
if (sps_pps)
|
||||||
memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
|
memcpy(*poutbuf + offset, sps_pps, sps_pps_size);
|
||||||
memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
|
memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size);
|
||||||
@ -77,7 +78,7 @@ static int h264_extradata_to_annexb(AVCodecContext *avctx, const int padding)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (unit_nb--) {
|
while (unit_nb--) {
|
||||||
void *tmp;
|
int err;
|
||||||
|
|
||||||
unit_size = AV_RB16(extradata);
|
unit_size = AV_RB16(extradata);
|
||||||
total_size += unit_size + 4;
|
total_size += unit_size + 4;
|
||||||
@ -93,12 +94,8 @@ static int h264_extradata_to_annexb(AVCodecContext *avctx, const int padding)
|
|||||||
av_free(out);
|
av_free(out);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
tmp = av_realloc(out, total_size + padding);
|
if ((err = av_reallocp(&out, total_size + padding)) < 0)
|
||||||
if (!tmp) {
|
return err;
|
||||||
av_free(out);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
out = tmp;
|
|
||||||
memcpy(out + total_size - unit_size - 4, nalu_header, 4);
|
memcpy(out + total_size - unit_size - 4, nalu_header, 4);
|
||||||
memcpy(out + total_size - unit_size, extradata + 2, unit_size);
|
memcpy(out + total_size - unit_size, extradata + 2, unit_size);
|
||||||
extradata += 2 + unit_size;
|
extradata += 2 + unit_size;
|
||||||
|
@ -59,18 +59,14 @@ typedef struct LAMEContext {
|
|||||||
static int realloc_buffer(LAMEContext *s)
|
static int realloc_buffer(LAMEContext *s)
|
||||||
{
|
{
|
||||||
if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) {
|
if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) {
|
||||||
uint8_t *tmp;
|
int new_size = s->buffer_index + 2 * BUFFER_SIZE, err;
|
||||||
int new_size = s->buffer_index + 2 * BUFFER_SIZE;
|
|
||||||
|
|
||||||
av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", s->buffer_size,
|
av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", s->buffer_size,
|
||||||
new_size);
|
new_size);
|
||||||
tmp = av_realloc(s->buffer, new_size);
|
if ((err = av_reallocp(&s->buffer, new_size)) < 0) {
|
||||||
if (!tmp) {
|
|
||||||
av_freep(&s->buffer);
|
|
||||||
s->buffer_size = s->buffer_index = 0;
|
s->buffer_size = s->buffer_index = 0;
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
}
|
}
|
||||||
s->buffer = tmp;
|
|
||||||
s->buffer_size = new_size;
|
s->buffer_size = new_size;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -293,6 +293,7 @@ static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
|
|
||||||
/* Now check to see if we have any output from the encoder. */
|
/* Now check to see if we have any output from the encoder. */
|
||||||
while (go) {
|
while (go) {
|
||||||
|
int err;
|
||||||
SchroStateEnum state;
|
SchroStateEnum state;
|
||||||
state = schro_encoder_wait(encoder);
|
state = schro_encoder_wait(encoder);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -307,8 +308,12 @@ static int libschroedinger_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
* be able to set the pts correctly. So we don't write data
|
* be able to set the pts correctly. So we don't write data
|
||||||
* to the frame output queue until we actually have a frame
|
* to the frame output queue until we actually have a frame
|
||||||
*/
|
*/
|
||||||
p_schro_params->enc_buf = av_realloc(p_schro_params->enc_buf,
|
if ((err = av_reallocp(&p_schro_params->enc_buf,
|
||||||
p_schro_params->enc_buf_size + enc_buf->length);
|
p_schro_params->enc_buf_size +
|
||||||
|
enc_buf->length)) < 0) {
|
||||||
|
p_schro_params->enc_buf_size = 0;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
|
memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
|
||||||
enc_buf->data, enc_buf->length);
|
enc_buf->data, enc_buf->length);
|
||||||
|
@ -58,31 +58,26 @@ static int concatenate_packet(unsigned int* offset,
|
|||||||
const ogg_packet* packet)
|
const ogg_packet* packet)
|
||||||
{
|
{
|
||||||
const char* message = NULL;
|
const char* message = NULL;
|
||||||
uint8_t* newdata = NULL;
|
|
||||||
int newsize = avc_context->extradata_size + 2 + packet->bytes;
|
int newsize = avc_context->extradata_size + 2 + packet->bytes;
|
||||||
int ret;
|
int err = AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
if (packet->bytes < 0) {
|
if (packet->bytes < 0) {
|
||||||
message = "ogg_packet has negative size";
|
message = "ogg_packet has negative size";
|
||||||
ret = AVERROR_INVALIDDATA;
|
|
||||||
} else if (packet->bytes > 0xffff) {
|
} else if (packet->bytes > 0xffff) {
|
||||||
message = "ogg_packet is larger than 65535 bytes";
|
message = "ogg_packet is larger than 65535 bytes";
|
||||||
ret = AVERROR_INVALIDDATA;
|
|
||||||
} else if (newsize < avc_context->extradata_size) {
|
} else if (newsize < avc_context->extradata_size) {
|
||||||
message = "extradata_size would overflow";
|
message = "extradata_size would overflow";
|
||||||
ret = AVERROR_INVALIDDATA;
|
|
||||||
} else {
|
} else {
|
||||||
newdata = av_realloc(avc_context->extradata, newsize);
|
if ((err = av_reallocp(&avc_context->extradata, newsize)) < 0) {
|
||||||
if (!newdata)
|
avc_context->extradata_size = 0;
|
||||||
message = "av_realloc failed";
|
message = "av_realloc failed";
|
||||||
ret = AVERROR(ENOMEM);
|
}
|
||||||
}
|
}
|
||||||
if (message) {
|
if (message) {
|
||||||
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
|
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message);
|
||||||
return ret;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
avc_context->extradata = newdata;
|
|
||||||
avc_context->extradata_size = newsize;
|
avc_context->extradata_size = newsize;
|
||||||
AV_WB16(avc_context->extradata + (*offset), packet->bytes);
|
AV_WB16(avc_context->extradata + (*offset), packet->bytes);
|
||||||
*offset += 2;
|
*offset += 2;
|
||||||
|
@ -638,11 +638,13 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out,
|
|||||||
break;
|
break;
|
||||||
case VPX_CODEC_STATS_PKT: {
|
case VPX_CODEC_STATS_PKT: {
|
||||||
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
|
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
|
||||||
stats->buf = av_realloc_f(stats->buf, 1,
|
int err;
|
||||||
stats->sz + pkt->data.twopass_stats.sz);
|
if ((err = av_reallocp(&stats->buf,
|
||||||
if (!stats->buf) {
|
stats->sz +
|
||||||
|
pkt->data.twopass_stats.sz)) < 0) {
|
||||||
|
stats->sz = 0;
|
||||||
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
|
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
}
|
}
|
||||||
memcpy((uint8_t*)stats->buf + stats->sz,
|
memcpy((uint8_t*)stats->buf + stats->sz,
|
||||||
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
|
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
|
||||||
|
@ -122,9 +122,7 @@ static av_cold int shorten_decode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
static int allocate_buffers(ShortenContext *s)
|
static int allocate_buffers(ShortenContext *s)
|
||||||
{
|
{
|
||||||
int i, chan;
|
int i, chan, err;
|
||||||
int *coeffs;
|
|
||||||
void *tmp_ptr;
|
|
||||||
|
|
||||||
for (chan = 0; chan < s->channels; chan++) {
|
for (chan = 0; chan < s->channels; chan++) {
|
||||||
if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
|
if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
|
||||||
@ -138,26 +136,21 @@ static int allocate_buffers(ShortenContext *s)
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_ptr =
|
if ((err = av_reallocp(&s->offset[chan],
|
||||||
av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
|
sizeof(int32_t) *
|
||||||
if (!tmp_ptr)
|
FFMAX(1, s->nmean))) < 0)
|
||||||
return AVERROR(ENOMEM);
|
return err;
|
||||||
s->offset[chan] = tmp_ptr;
|
|
||||||
|
|
||||||
tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
|
if ((err = av_reallocp(&s->decoded_base[chan], (s->blocksize + s->nwrap) *
|
||||||
sizeof(s->decoded_base[0][0]));
|
sizeof(s->decoded_base[0][0]))) < 0)
|
||||||
if (!tmp_ptr)
|
return err;
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
s->decoded_base[chan] = tmp_ptr;
|
|
||||||
for (i = 0; i < s->nwrap; i++)
|
for (i = 0; i < s->nwrap; i++)
|
||||||
s->decoded_base[chan][i] = 0;
|
s->decoded_base[chan][i] = 0;
|
||||||
s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
|
s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
|
if ((err = av_reallocp(&s->coeffs, s->nwrap * sizeof(*s->coeffs))) < 0)
|
||||||
if (!coeffs)
|
return err;
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
s->coeffs = coeffs;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user