1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

avcodec/pngenc: Avoid potentially truncating integers

So use 64bits for max_packet_size instead of size_t which might be
32 bits; this is consistent with ff_alloc_packet().
Also remove a redundant size check (ff_alloc_packet() already
checks for that).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2022-03-15 07:51:29 +01:00
parent 2d368392a5
commit db57a5370b

View File

@@ -528,7 +528,7 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt,
PNGEncContext *s = avctx->priv_data; PNGEncContext *s = avctx->priv_data;
int ret; int ret;
int enc_row_size; int enc_row_size;
size_t max_packet_size; uint64_t max_packet_size;
enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3); enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3);
max_packet_size = max_packet_size =
@@ -537,8 +537,6 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt,
enc_row_size + enc_row_size +
12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE) 12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE)
); );
if (max_packet_size > INT_MAX)
return AVERROR(ENOMEM);
ret = ff_alloc_packet(avctx, pkt, max_packet_size); ret = ff_alloc_packet(avctx, pkt, max_packet_size);
if (ret < 0) if (ret < 0)
return ret; return ret;
@@ -845,7 +843,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
PNGEncContext *s = avctx->priv_data; PNGEncContext *s = avctx->priv_data;
int ret; int ret;
int enc_row_size; int enc_row_size;
size_t max_packet_size; uint64_t max_packet_size;
APNGFctlChunk fctl_chunk = {0}; APNGFctlChunk fctl_chunk = {0};
if (pict && s->color_type == PNG_COLOR_TYPE_PALETTE) { if (pict && s->color_type == PNG_COLOR_TYPE_PALETTE) {