From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/3] avcodec: use AV_PKT_MAX_PAYLOAD_SIZE Date: Wed, 21 Jun 2023 17:46:57 -0300 Message-ID: <20230621204658.2742-2-jamrial@gmail.com> (raw) In-Reply-To: <20230621204658.2742-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/avpacket.c | 6 +++--- libavcodec/dvdsub_parser.c | 2 +- libavcodec/encode.c | 10 +++++----- libavcodec/ffv1enc.c | 4 ++-- libavcodec/h264_mp4toannexb_bsf.c | 2 +- libavcodec/libopenjpegenc.c | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 5fef65e97a..cdf7edc23c 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -82,7 +82,7 @@ void av_packet_free(AVPacket **pkt) static int packet_alloc(AVBufferRef **buf, int size) { int ret; - if (size < 0 || size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + if (size < 0 || size >= AV_PKT_MAX_PAYLOAD_SIZE) return AVERROR(EINVAL); ret = av_buffer_realloc(buf, size + AV_INPUT_BUFFER_PADDING_SIZE); @@ -120,7 +120,7 @@ void av_shrink_packet(AVPacket *pkt, int size) int av_grow_packet(AVPacket *pkt, int grow_by) { int new_size; - av_assert0((unsigned)pkt->size <= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE); + av_assert0((unsigned)pkt->size <= AV_PKT_MAX_PAYLOAD_SIZE); if ((unsigned)grow_by > INT_MAX - (pkt->size + AV_INPUT_BUFFER_PADDING_SIZE)) return AVERROR(ENOMEM); @@ -170,7 +170,7 @@ int av_grow_packet(AVPacket *pkt, int grow_by) int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size) { - if (size >= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + if (size >= AV_PKT_MAX_PAYLOAD_SIZE) return AVERROR(EINVAL); pkt->buf = av_buffer_create(data, size + AV_INPUT_BUFFER_PADDING_SIZE, diff --git a/libavcodec/dvdsub_parser.c b/libavcodec/dvdsub_parser.c index 8871b6a383..1589a543df 100644 --- a/libavcodec/dvdsub_parser.c +++ b/libavcodec/dvdsub_parser.c @@ -52,7 +52,7 @@ static int dvdsub_parse(AVCodecParserContext *s, if (pc->packet_len == 0) /* HD-DVD subpicture packet */ pc->packet_len = AV_RB32(buf+2); av_freep(&pc->packet); - if ((unsigned)pc->packet_len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { + if ((unsigned)pc->packet_len > AV_PKT_MAX_PAYLOAD_SIZE) { av_log(avctx, AV_LOG_ERROR, "packet length %d is invalid\n", pc->packet_len); return buf_size; } diff --git a/libavcodec/encode.c b/libavcodec/encode.c index ab5f889615..7bc14c7fc5 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -34,9 +34,9 @@ int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size) { - if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { - av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n", - size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE); + if (size < 0 || size > AV_PKT_MAX_PAYLOAD_SIZE) { + av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %"SIZE_SPECIFIER")\n", + size, AV_PKT_MAX_PAYLOAD_SIZE); return AVERROR(EINVAL); } @@ -58,7 +58,7 @@ int avcodec_default_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, in { int ret; - if (avpkt->size < 0 || avpkt->size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + if (avpkt->size < 0 || avpkt->size > AV_PKT_MAX_PAYLOAD_SIZE) return AVERROR(EINVAL); if (avpkt->data || avpkt->buf) { @@ -80,7 +80,7 @@ int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, i { int ret; - if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) + if (size < 0 || size > AV_PKT_MAX_PAYLOAD_SIZE) return AVERROR(EINVAL); av_assert0(!avpkt->data && !avpkt->buf); diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 746f717568..b1c9f19e83 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1152,9 +1152,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, if (f->version > 3) maxsize = AV_INPUT_BUFFER_MIN_SIZE + avctx->width*avctx->height*3LL*4; - if (maxsize > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32) { + if (maxsize > AV_PKT_MAX_PAYLOAD_SIZE - 32) { av_log(avctx, AV_LOG_WARNING, "Cannot allocate worst case packet size, the encoding could fail\n"); - maxsize = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 32; + maxsize = AV_PKT_MAX_PAYLOAD_SIZE - 32; } if ((ret = ff_alloc_packet(avctx, pkt, maxsize)) < 0) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index d11be455c2..20142b90aa 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -269,7 +269,7 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) } while (buf < buf_end); if (!j) { - if (out_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { + if (out_size > AV_PKT_MAX_PAYLOAD_SIZE) { ret = AVERROR_INVALIDDATA; goto fail; } diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c index 009c7a4377..c88c3d0102 100644 --- a/libavcodec/libopenjpegenc.c +++ b/libavcodec/libopenjpegenc.c @@ -73,7 +73,7 @@ static OPJ_SIZE_T stream_write(void *out_buffer, OPJ_SIZE_T nb_bytes, void *user int remaining = packet->size - writer->pos; if (nb_bytes > remaining) { OPJ_SIZE_T needed = nb_bytes - remaining; - int max_growth = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - packet->size; + int max_growth = AV_PKT_MAX_PAYLOAD_SIZE - packet->size; if (needed > max_growth) { return (OPJ_SIZE_T)-1; } @@ -101,7 +101,7 @@ static OPJ_OFF_T stream_skip(OPJ_OFF_T nb_bytes, void *user_data) int remaining = packet->size - writer->pos; if (nb_bytes > remaining) { OPJ_SIZE_T needed = nb_bytes - remaining; - int max_growth = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - packet->size; + int max_growth = AV_PKT_MAX_PAYLOAD_SIZE - packet->size; if (needed > max_growth) { return (OPJ_SIZE_T)-1; } @@ -122,7 +122,7 @@ static OPJ_BOOL stream_seek(OPJ_OFF_T nb_bytes, void *user_data) return OPJ_FALSE; } if (nb_bytes > packet->size) { - if (nb_bytes > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE || + if (nb_bytes > AV_PKT_MAX_PAYLOAD_SIZE || av_grow_packet(packet, (int)nb_bytes - packet->size)) { return OPJ_FALSE; } -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-06-21 20:47 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-21 20:46 [FFmpeg-devel] [PATCH 1/3] avcodec/packet: add a define for the max buffer size a packet can hold James Almer 2023-06-21 20:46 ` James Almer [this message] 2023-06-21 20:46 ` [FFmpeg-devel] [PATCH 3/3] avformat: use AV_PKT_MAX_PAYLOAD_SIZE James Almer 2023-06-27 7:23 ` [FFmpeg-devel] [PATCH 1/3] avcodec/packet: add a define for the max buffer size a packet can hold Anton Khirnov 2023-06-27 14:39 ` James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230621204658.2742-2-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git