diff -ruN a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c --- a/libavcodec/aacsbr_template.c 2026-08-03 18:14:47 +++ b/libavcodec/aacsbr_template.c 2026-11-10 15:39:52 @@ -1206,12 +1206,11 @@ return 0; } -int ff_aac_sbr_decode_usac_data(AACDecContext *ac, ChannelElement *che, - AACUsacElemConfig *ue, GetBitContext *gb, - int sbr_ch, int indep_flag) +static int read_usac_sbr_data(AACDecContext *ac, SpectralBandReplication *sbr, + AACUsacElemConfig *ue, GetBitContext *gb, + int sbr_ch, int indep_flag) { int ret; - SpectralBandReplication *sbr = get_sbr(che); int info_present = 1; int header_present = 1; @@ -1351,6 +1350,19 @@ } return 0; +} + +int ff_aac_sbr_decode_usac_data(AACDecContext *ac, ChannelElement *che, + AACUsacElemConfig *ue, GetBitContext *gb, + int sbr_ch, int indep_flag) +{ + SpectralBandReplication *sbr = get_sbr(che); + int ret = read_usac_sbr_data(ac, sbr, ue, gb, sbr_ch, indep_flag); + + if (ret < 0) + sbr_turnoff(sbr); + + return ret; } #endif diff -ruN a/libavcodec/bitpacked_dec.c b/libavcodec/bitpacked_dec.c --- a/libavcodec/bitpacked_dec.c 2026-08-03 18:14:47 +++ b/libavcodec/bitpacked_dec.c 2026-11-10 15:39:28 @@ -42,18 +42,18 @@ { int ret; + ret = av_image_fill_arrays(frame->data, frame->linesize, avpkt->data, + avctx->pix_fmt, avctx->width, avctx->height, 1); + if (ret < 0) + return ret; + if (ret > avpkt->size) + return AVERROR_INVALIDDATA; + /* there is no need to copy as the data already match * a known pixel format */ frame->buf[0] = av_buffer_ref(avpkt->buf); if (!frame->buf[0]) { return AVERROR(ENOMEM); - } - - ret = av_image_fill_arrays(frame->data, frame->linesize, avpkt->data, - avctx->pix_fmt, avctx->width, avctx->height, 1); - if (ret < 0) { - av_buffer_unref(&frame->buf[0]); - return ret; } return 0; diff -ruN a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c --- a/libavcodec/cbs_h266_syntax_template.c 2026-09-17 22:29:35 +++ b/libavcodec/cbs_h266_syntax_template.c 2026-11-10 15:39:52 @@ -1113,12 +1113,12 @@ flag(sps_conformance_window_flag); if (current->sps_conformance_window_flag) { - uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c; - uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c; - ue(sps_conf_win_left_offset, 0, width); - ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset); - ue(sps_conf_win_top_offset, 0, height); - ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset); + uint16_t max_offsets_x = (current->sps_pic_width_max_in_luma_samples - 1) / sub_width_c; + uint16_t max_offsets_y = (current->sps_pic_height_max_in_luma_samples - 1) / sub_height_c; + ue(sps_conf_win_left_offset, 0, max_offsets_x); + ue(sps_conf_win_right_offset, 0, max_offsets_x - current->sps_conf_win_left_offset); + ue(sps_conf_win_top_offset, 0, max_offsets_y); + ue(sps_conf_win_bottom_offset, 0, max_offsets_y - current->sps_conf_win_top_offset); } else { infer(sps_conf_win_left_offset, 0); infer(sps_conf_win_right_offset, 0); @@ -1584,7 +1584,7 @@ flag(sps_virtual_boundaries_enabled_flag); if (current->sps_virtual_boundaries_enabled_flag) { - flag(sps_virtual_boundaries_present_flag); + u(1, sps_virtual_boundaries_present_flag, 0, !current->sps_res_change_in_clvs_allowed_flag); if (current->sps_virtual_boundaries_present_flag) { ue(sps_num_ver_virtual_boundaries, 0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS); diff -ruN a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c --- a/libavcodec/cbs_sei.c 2026-08-03 18:14:47 +++ b/libavcodec/cbs_sei.c 2026-11-10 15:39:52 @@ -279,11 +279,8 @@ list->messages = ptr; list->nb_messages_allocated = new_count; - - // Zero the newly-added entries. - memset(list->messages + old_count, 0, - (new_count - old_count) * sizeof(*list->messages)); } + memset(&list->messages[list->nb_messages], 0, sizeof(*list->messages)); ++list->nb_messages; return 0; } diff -ruN a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c --- a/libavcodec/dpxenc.c 2026-08-03 18:14:47 +++ b/libavcodec/dpxenc.c 2026-11-10 15:39:28 @@ -68,8 +68,12 @@ break; case AV_PIX_FMT_RGB48LE: case AV_PIX_FMT_RGB48BE: - if (avctx->bits_per_raw_sample) - s->bits_per_component = avctx->bits_per_raw_sample; + if (avctx->bits_per_raw_sample == 10) { + s->bits_per_component = 10; + } else if (avctx->bits_per_raw_sample && avctx->bits_per_raw_sample != 16) { + av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample); + return AVERROR(EINVAL); + } break; } diff -ruN a/libavcodec/dvbsubenc.c b/libavcodec/dvbsubenc.c --- a/libavcodec/dvbsubenc.c 2026-08-03 18:14:47 +++ b/libavcodec/dvbsubenc.c 2026-11-10 15:39:28 @@ -221,8 +221,8 @@ q = *pq; for (y = 0; y < h; y++) { - // Worst case line is 12 bits per value, + 3 bytes overhead - if (buf_size * 8 < w * 12 + 24) + // Worst case line is 12 bits per value, + 4 bytes overhead + if (buf_size * 8 < w * 12 + 32) return AVERROR_BUFFER_TOO_SMALL; line_begin = q; *q++ = 0x12; @@ -360,7 +360,7 @@ return AVERROR(EINVAL); } - if (buf_size < 6 + h->rects[clut_id]->nb_colors * 6) + if (buf_size < 8 + h->rects[clut_id]->nb_colors * 6) return AVERROR_BUFFER_TOO_SMALL; /* CLUT segment */ @@ -391,7 +391,7 @@ } bytestream_put_be16(&pseg_len, q - pseg_len - 2); - buf_size -= 6 + h->rects[clut_id]->nb_colors * 6; + buf_size -= 8 + h->rects[clut_id]->nb_colors * 6; } if (buf_size < h->num_rects * 22) diff -ruN a/libavcodec/encode.c b/libavcodec/encode.c --- a/libavcodec/encode.c 2026-08-03 18:14:47 +++ b/libavcodec/encode.c 2026-11-10 15:40:52 @@ -517,6 +517,17 @@ } } } + } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) { + /* UtilgruX backport of FFmpeg master (PR 25682, CVE-2026-125212/-125218/-125260/-125235/-125204): + reject video frames whose size or format differs from what the encoder was opened with. */ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format); + + if (!(desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && + (src->format != avctx->pix_fmt || + src->width != avctx->width || src->height != avctx->height)) { + av_log(avctx, AV_LOG_ERROR, "Frame size or pixel format does not match the encoder\n"); + return AVERROR(EINVAL); + } } ret = av_frame_ref(dst, src); diff -ruN a/libavcodec/exrenc.c b/libavcodec/exrenc.c --- a/libavcodec/exrenc.c 2026-08-03 18:14:47 +++ b/libavcodec/exrenc.c 2026-11-10 15:39:28 @@ -437,15 +437,17 @@ /* nothing to do */ break; case EXR_RLE: - encode_scanline_rle(s, frame); + ret = encode_scanline_rle(s, frame); break; case EXR_ZIP16: case EXR_ZIP1: - encode_scanline_zip(s, frame); + ret = encode_scanline_zip(s, frame); break; default: av_assert0(0); } + if (ret < 0) + return ret; switch (s->compression) { case EXR_RAW: diff -ruN a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c --- a/libavcodec/flashsvenc.c 2026-08-03 18:14:47 +++ b/libavcodec/flashsvenc.c 2026-11-10 15:39:52 @@ -62,6 +62,7 @@ typedef struct FlashSVContext { AVCodecContext *avctx; const uint8_t *previous_frame; + int previous_linesize; AVBufferRef *prev_frame_buf; int image_width, image_height; unsigned packet_size; @@ -71,14 +72,15 @@ } FlashSVContext; static int copy_region_enc(const uint8_t *sptr, uint8_t *dptr, int dx, int dy, - int h, int w, int stride, const uint8_t *pfptr) + int h, int w, int stride, const uint8_t *pfptr, + int pstride) { int i, j; int diff = 0; for (i = dx + h; i > dx; i--) { const uint8_t *nsptr = sptr + i * stride + dy * 3; - const uint8_t *npfptr = pfptr + i * stride + dy * 3; + const uint8_t *npfptr = pfptr + i * pstride + dy * 3; for (j = 0; j < w * 3; j++) { diff |= npfptr[j] ^ nsptr[j]; dptr[j] = nsptr[j]; @@ -132,7 +134,8 @@ static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf, int buf_size, int block_width, int block_height, - const uint8_t *previous_frame, int *I_frame) + const uint8_t *previous_frame, + int previous_linesize, int *I_frame) { PutBitContext pb; @@ -172,7 +175,8 @@ res = copy_region_enc(p->data[0], s->tmpblock, s->image_height - (y_pos + cur_blk_height + 1), x_pos, cur_blk_height, cur_blk_width, - p->linesize[0], previous_frame); + p->linesize[0], previous_frame, + previous_linesize); if (res || *I_frame) { unsigned long zsize = 3 * block_width * block_height + 12; @@ -209,6 +213,7 @@ { FlashSVContext * const s = avctx->priv_data; const uint8_t *prev_frame = s->previous_frame; + int prev_linesize = s->previous_linesize; int res; int I_frame = 0; int opt_w = 4, opt_h = 4; @@ -216,6 +221,7 @@ /* First frame needs to be a keyframe */ if (!s->previous_frame) { prev_frame = pict->data[0]; + prev_linesize = pict->linesize[0]; I_frame = 1; } @@ -231,7 +237,7 @@ pkt->size = encode_bitstream(s, pict, pkt->data, pkt->size, opt_w * 16, opt_h * 16, - prev_frame, &I_frame); + prev_frame, prev_linesize, &I_frame); //mark the frame type so the muxer can mux it correctly if (I_frame) { @@ -248,6 +254,7 @@ if (res < 0) return res; s->previous_frame = pict->data[0]; + s->previous_linesize = pict->linesize[0]; return 0; } diff -ruN a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c --- a/libavcodec/flicvideo.c 2026-08-03 18:14:47 +++ b/libavcodec/flicvideo.c 2026-11-10 15:39:28 @@ -61,28 +61,40 @@ #define FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE (0xAF13) static inline int check_pixel_ptr(ptrdiff_t ptr, int n, - ptrdiff_t limit, int direction) + ptrdiff_t lo, ptrdiff_t hi) { - if (( direction && ptr + n > limit) || - (!direction && ptr + n < limit)) + if (ptr < lo || ptr + n > hi) return AVERROR_INVALIDDATA; return 0; } #define CHECK_PIXEL_PTR(n) \ { \ - ret = check_pixel_ptr(pixel_ptr, (n), pixel_limit, direction); \ + ret = check_pixel_ptr(pixel_ptr, (n), pixel_lo, pixel_hi); \ if (ret < 0) \ return ret; \ } #define CHECK_Y_PTR() \ { \ - ret = check_pixel_ptr(y_ptr, 0, pixel_limit, direction); \ + ret = check_pixel_ptr(y_ptr, 0, pixel_lo, pixel_hi); \ if (ret < 0) \ return ret; \ } +static void pixel_range(const AVFrame *frame, ptrdiff_t *lo, ptrdiff_t *hi) +{ + ptrdiff_t linesize = frame->linesize[0]; + + if (linesize > 0) { + *lo = 0; + *hi = frame->height * linesize; + } else { + *lo = (frame->height - 1) * linesize; + *hi = -linesize; + } +} + typedef struct FlicDecodeContext { AVCodecContext *avctx; AVFrame *frame; @@ -178,7 +190,7 @@ unsigned int chunk_size; int chunk_type; - int i, j, ret, direction; + int i, j, ret; int lines; int compressed_lines; @@ -189,16 +201,15 @@ int pixel_skip; int pixel_countdown; unsigned char *pixels; - ptrdiff_t pixel_limit; + ptrdiff_t pixel_lo, pixel_hi; bytestream2_init(&g2, buf, buf_size); if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) return ret; - direction = s->frame->linesize[0] > 0; pixels = s->frame->data[0]; - pixel_limit = s->avctx->height * s->frame->linesize[0]; + pixel_range(s->frame, &pixel_lo, &pixel_hi); if (buf_size < 16 || buf_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) return AVERROR_INVALIDDATA; frame_size = bytestream2_get_le32(&g2); @@ -373,7 +384,7 @@ unsigned int chunk_size; int chunk_type; - int i, j, ret, direction; + int i, j, ret; int color_packets; int color_changes; @@ -389,16 +400,15 @@ int pixel_skip; int pixel_countdown; unsigned char *pixels; - ptrdiff_t pixel_limit; + ptrdiff_t pixel_lo, pixel_hi; bytestream2_init(&g2, buf, buf_size); if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) return ret; - direction = s->frame->linesize[0] > 0; pixels = s->frame->data[0]; - pixel_limit = s->avctx->height * s->frame->linesize[0]; + pixel_range(s->frame, &pixel_lo, &pixel_hi); if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + AV_INPUT_BUFFER_PADDING_SIZE)) return AVERROR_INVALIDDATA; frame_size = bytestream2_get_le32(&g2); @@ -642,7 +652,7 @@ "has incorrect size, skipping chunk\n", chunk_size - 6); bytestream2_skip(&g2, chunk_size - 6); } else { - for (y_ptr = 0; check_pixel_ptr(y_ptr, s->avctx->width, pixel_limit, direction) == 0; + for (y_ptr = 0; check_pixel_ptr(y_ptr, s->avctx->width, pixel_lo, pixel_hi) == 0; y_ptr += s->frame->linesize[0]) { bytestream2_get_buffer(&g2, &pixels[y_ptr], s->avctx->width); @@ -711,7 +721,7 @@ unsigned int chunk_size; int chunk_type; - int i, j, ret, direction; + int i, j, ret; int lines; int compressed_lines; @@ -722,16 +732,15 @@ int pixel_countdown; unsigned char *pixels; int pixel; - ptrdiff_t pixel_limit; + ptrdiff_t pixel_lo, pixel_hi; bytestream2_init(&g2, buf, buf_size); if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) return ret; - direction = s->frame->linesize[0] > 0; pixels = s->frame->data[0]; - pixel_limit = s->avctx->height * s->frame->linesize[0]; + pixel_range(s->frame, &pixel_lo, &pixel_hi); frame_size = bytestream2_get_le32(&g2); bytestream2_skip(&g2, 2); /* skip the magic number */ @@ -881,8 +890,9 @@ pixel_ptr = y_ptr; pixel_countdown = s->avctx->width; while (pixel_countdown > 0) { - *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]); + *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&pixels[pixel_ptr]); pixel_ptr += 2; + pixel_countdown--; } #endif y_ptr += s->frame->linesize[0]; @@ -944,7 +954,7 @@ if (bytestream2_get_bytes_left(&g2) < 2 * s->avctx->width * s->avctx->height ) return AVERROR_INVALIDDATA; - for (y_ptr = 0; check_pixel_ptr(y_ptr, 2*s->avctx->width, pixel_limit, direction) == 0; + for (y_ptr = 0; check_pixel_ptr(y_ptr, 2*s->avctx->width, pixel_lo, pixel_hi) == 0; y_ptr += s->frame->linesize[0]) { pixel_countdown = s->avctx->width; @@ -1011,7 +1021,7 @@ unsigned int chunk_size; int chunk_type; - int i, j, ret, direction; + int i, j, ret; int lines; int compressed_lines; @@ -1022,16 +1032,15 @@ int pixel_countdown; unsigned char *pixels; int pixel; - ptrdiff_t pixel_limit; + ptrdiff_t pixel_lo, pixel_hi; bytestream2_init(&g2, buf, buf_size); if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) return ret; - direction = s->frame->linesize[0] > 0; pixels = s->frame->data[0]; - pixel_limit = s->avctx->height * s->frame->linesize[0]; + pixel_range(s->frame, &pixel_lo, &pixel_hi); frame_size = bytestream2_get_le32(&g2); bytestream2_skip(&g2, 2); /* skip the magic number */ @@ -1230,7 +1239,7 @@ "bigger than image, skipping chunk\n", chunk_size - 6); bytestream2_skip(&g2, chunk_size - 6); } else { - for (y_ptr = 0; check_pixel_ptr(y_ptr, 3*s->avctx->width, pixel_limit, direction) == 0; + for (y_ptr = 0; check_pixel_ptr(y_ptr, 3*s->avctx->width, pixel_lo, pixel_hi) == 0; y_ptr += s->frame->linesize[0]) { bytestream2_get_buffer(&g2, pixels + y_ptr, 3*s->avctx->width); diff -ruN a/libavcodec/gif.c b/libavcodec/gif.c --- a/libavcodec/gif.c 2026-08-03 18:14:47 +++ b/libavcodec/gif.c 2026-11-10 15:39:28 @@ -300,6 +300,7 @@ int x_start = 0, y_start = 0, trans = s->transparent_index; int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) && s->last_frame && !palette; const uint8_t *ptr; + int ptr_linesize = linesize; uint32_t shrunk_palette[AVPALETTE_COUNT]; uint8_t map[AVPALETTE_COUNT] = { 0 }; size_t shrunk_palette_count = 0; @@ -402,14 +403,15 @@ if (shrunk_palette_count) { if (!s->shrunk_buf) { - s->shrunk_buf = av_malloc(avctx->height * linesize); + s->shrunk_buf = av_malloc(avctx->height * avctx->width); if (!s->shrunk_buf) { av_log(avctx, AV_LOG_ERROR, "Could not allocated remapped frame buffer.\n"); return AVERROR(ENOMEM); } } - remap_frame_to_palette(buf, linesize, s->shrunk_buf, linesize, avctx->width, avctx->height, map); - ptr = s->shrunk_buf + y_start*linesize + x_start; + remap_frame_to_palette(buf, linesize, s->shrunk_buf, avctx->width, avctx->width, avctx->height, map); + ptr = s->shrunk_buf + y_start*avctx->width + x_start; + ptr_linesize = avctx->width; } else { ptr = buf + y_start*linesize + x_start; } @@ -423,13 +425,13 @@ if (ref[x] == ptr[x]) s->tmpl[x] = trans; len += ff_lzw_encode(s->lzw, s->tmpl, width); - ptr += linesize; + ptr += ptr_linesize; ref += ref_linesize; } } else { for (y = 0; y < height; y++) { len += ff_lzw_encode(s->lzw, ptr, width); - ptr += linesize; + ptr += ptr_linesize; } } len += ff_lzw_encode_flush(s->lzw); @@ -499,8 +501,10 @@ } } - gif_image_write_image(avctx, &outbuf_ptr, end, palette, - pict->data[0], pict->linesize[0], pkt); + ret = gif_image_write_image(avctx, &outbuf_ptr, end, palette, + pict->data[0], pict->linesize[0], pkt); + if (ret < 0) + return ret; if (!s->last_frame && !s->image) { s->last_frame = av_frame_alloc(); if (!s->last_frame) diff -ruN a/libavcodec/hapdec.c b/libavcodec/hapdec.c --- a/libavcodec/hapdec.c 2026-08-03 18:14:47 +++ b/libavcodec/hapdec.c 2026-11-10 15:39:28 @@ -187,6 +187,7 @@ ctx->tex_size = 0; for (i = 0; i < ctx->chunk_count; i++) { HapChunk *chunk = &ctx->chunks[i]; + int64_t uncompressed_size; /* Check the compressed buffer is valid */ if (chunk->compressed_offset + (uint64_t)chunk->compressed_size > bytestream2_get_bytes_left(gbc)) @@ -199,20 +200,21 @@ /* Fill out uncompressed size */ if (chunk->compressor == HAP_COMP_SNAPPY) { GetByteContext gbc_tmp; - int64_t uncompressed_size; bytestream2_init(&gbc_tmp, gbc->buffer + chunk->compressed_offset, chunk->compressed_size); uncompressed_size = ff_snappy_peek_uncompressed_length(&gbc_tmp); if (uncompressed_size < 0) { return uncompressed_size; } - chunk->uncompressed_size = uncompressed_size; } else if (chunk->compressor == HAP_COMP_NONE) { - chunk->uncompressed_size = chunk->compressed_size; + uncompressed_size = chunk->compressed_size; } else { return AVERROR_INVALIDDATA; } - ctx->tex_size += chunk->uncompressed_size; + if (uncompressed_size > INT_MAX - ctx->tex_size) + return AVERROR_INVALIDDATA; + chunk->uncompressed_size = uncompressed_size; + ctx->tex_size += uncompressed_size; } av_log(avctx, AV_LOG_DEBUG, "%s compressor\n", compressorstr); diff -ruN a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c --- a/libavcodec/huffyuvdec.c 2026-09-17 22:29:35 +++ b/libavcodec/huffyuvdec.c 2026-11-10 15:39:52 @@ -757,7 +757,7 @@ } CLOSE_READER(re, &s->gb); } else { - if (count >= (get_bits_left(&s->gb)) / (32 * 2)) { + if (count >= (get_bits_left(&s->gb)) / (33 * 2)) { for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { READ_2PIX_PLANE16(s->temp16[0][2 * i], s->temp16[0][2 * i + 1], plane); } diff -ruN a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c --- a/libavcodec/huffyuvenc.c 2026-09-17 22:29:35 +++ b/libavcodec/huffyuvenc.c 2026-11-10 15:39:52 @@ -370,6 +370,13 @@ return AVERROR(EINVAL); } + if (s->predictor == MEDIAN && s->version <= 2 && + (avctx->width < 4 || + AV_CEIL_RSHIFT(avctx->height, s->chroma_v_shift) < 2 + s->interlaced)) { + av_log(avctx, AV_LOG_ERROR, "Frame too small for the median predictor\n"); + return AVERROR(EINVAL); + } + avctx->extradata[0] = s->predictor | (s->decorrelate << 6); avctx->extradata[2] = s->interlaced ? 0x10 : 0x20; if (s->context) @@ -904,7 +911,7 @@ if (s->predictor==MEDIAN) { int lefttop; y = 1; - if (s->interlaced) { + if (s->interlaced && h > 1) { left = sub_left_prediction(s, s->temp[0], p->data[plane] + p->linesize[plane], w , left); encode_plane_bitstream(s, w, plane); diff -ruN a/libavcodec/lcldec.c b/libavcodec/lcldec.c --- a/libavcodec/lcldec.c 2026-08-11 23:05:22 +++ b/libavcodec/lcldec.c 2026-11-10 15:39:52 @@ -283,6 +283,10 @@ break; } } else if (c->flags & FLAG_MULTITHREAD) { + if (len < 8) { + av_log(avctx, AV_LOG_ERROR, "len %d is too small\n", len); + return AVERROR_INVALIDDATA; + } mthread_inlen = AV_RL32(buf); mthread_inlen = FFMIN(mthread_inlen, len - 8); mthread_outlen = AV_RL32(buf + 4); diff -ruN a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c --- a/libavcodec/mjpegdec.c 2026-08-03 18:14:47 +++ b/libavcodec/mjpegdec.c 2026-11-10 15:39:52 @@ -2761,6 +2761,14 @@ } } } + if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && + (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || + avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && + avctx->coded_height > s->orig_height) { + frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres); + frame->crop_top = frame->height - avctx->height; + } + if (s->flipped && !s->rgb && !s->bayer) { ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &hshift, &vshift); if (ret) @@ -2871,14 +2879,6 @@ av_exif_free(&s->exif_metadata); if (ret < 0) av_log(avctx, AV_LOG_WARNING, "couldn't attach EXIF metadata\n"); - } - - if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && - (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || - avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && - avctx->coded_height > s->orig_height) { - frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres); - frame->crop_top = frame->height - avctx->height; } the_end_no_picture: diff -ruN a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c --- a/libavcodec/nellymoserenc.c 2026-08-03 18:14:47 +++ b/libavcodec/nellymoserenc.c 2026-11-10 15:39:51 @@ -235,7 +235,7 @@ return tmp * tmp; } -static void get_exponent_dynamic(NellyMoserEncodeContext *s, float *cand, int *idx_table) +static int get_exponent_dynamic(NellyMoserEncodeContext *s, float *cand, int *idx_table) { int i, j, band, best_idx; float power_candidate, best_val; @@ -243,9 +243,9 @@ float (*opt )[OPT_SIZE] = s->opt ; uint8_t(*path)[OPT_SIZE] = s->path; - for (i = 0; i < NELLY_BANDS * OPT_SIZE; i++) { - opt[0][i] = INFINITY; - } + for (band = 0; band < NELLY_BANDS; band++) + for (i = 0; i < OPT_SIZE; i++) + opt[band][i] = INFINITY; for (i = 0; i < 64; i++) { opt[0][ff_nelly_init_table[i]] = distance(cand[0], ff_nelly_init_table[i], 0); @@ -257,9 +257,9 @@ float tmp; int idx_min, idx_max, idx; power_candidate = cand[band]; - for (q = 1000; !c && q < OPT_SIZE; q <<= 2) { + for (q = 1000; !c && q < 2 * OPT_SIZE; q <<= 2) { idx_min = FFMAX(0, cand[band] - q); - idx_max = FFMIN(OPT_SIZE, cand[band - 1] + q); + idx_max = FFMIN(OPT_SIZE - 1, cand[band - 1] + q); for (i = FFMAX(0, cand[band - 1] - q); i < FFMIN(OPT_SIZE, cand[band - 1] + q); i++) { if ( isinf(opt[band - 1][i]) ) continue; @@ -278,7 +278,6 @@ } } } - av_assert1(c); //FIXME } best_val = INFINITY; @@ -290,12 +289,15 @@ best_idx = i; } } + if (best_idx < 0) + return AVERROR(EINVAL); for (band = NELLY_BANDS - 1; band >= 0; band--) { idx_table[band] = path[band][best_idx]; if (band) { best_idx -= ff_nelly_delta_table[path[band][best_idx]]; } } + return 0; } /** @@ -304,7 +306,7 @@ * @param output output buffer * @param output_size size of output buffer */ -static void encode_block(NellyMoserEncodeContext *s, unsigned char *output, int output_size) +static int encode_block(NellyMoserEncodeContext *s, unsigned char *output, int output_size) { PutBitContext pb; int i, j, band, block, best_idx, power_idx = 0; @@ -326,10 +328,16 @@ } cand[band] = log2(FFMAX(1.0, coeff_sum / (ff_nelly_band_sizes_table[band] << 7))) * 1024.0; + if (!isfinite(cand[band])) { + av_log(s->avctx, AV_LOG_ERROR, "Input contains NaN/+-Inf\n"); + return AVERROR(EINVAL); + } } if (s->avctx->trellis) { - get_exponent_dynamic(s, cand, idx_table); + int ret = get_exponent_dynamic(s, cand, idx_table); + if (ret < 0) + return ret; } else { get_exponent_greedy(s, cand, idx_table); } @@ -343,6 +351,8 @@ power_idx = ff_nelly_init_table[idx_table[0]]; put_bits(&pb, 6, idx_table[0]); } + if (power_idx >= (31 - POW_TABLE_OFFSET) << 11) + return AVERROR(EINVAL); power_val = pow_table[power_idx & 0x7FF] / (1 << ((power_idx >> 11) + POW_TABLE_OFFSET)); for (j = 0; j < ff_nelly_band_sizes_table[band]; i++, j++) { s->mdct_out[i] *= power_val; @@ -376,6 +386,7 @@ flush_put_bits(&pb); memset(put_bits_ptr(&pb), 0, output + output_size - put_bits_ptr(&pb)); + return 0; } static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, @@ -406,7 +417,8 @@ if ((ret = ff_get_encode_buffer(avctx, avpkt, NELLY_BLOCK_LEN, 0)) < 0) return ret; - encode_block(s, avpkt->data, avpkt->size); + if ((ret = encode_block(s, avpkt->data, avpkt->size)) < 0) + return ret; /* Get the next frame pts/duration */ ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, diff -ruN a/libavcodec/null.c b/libavcodec/null.c --- a/libavcodec/null.c 2026-08-03 18:14:47 +++ b/libavcodec/null.c 2026-11-10 15:39:52 @@ -70,6 +70,7 @@ CODEC_LONG_NAME("null video"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_VNULL, + .p.capabilities = AV_CODEC_CAP_PARAM_CHANGE, FF_CODEC_ENCODE_CB(null_encode), }; #endif diff -ruN a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c --- a/libavcodec/pcxenc.c 2026-08-03 18:14:47 +++ b/libavcodec/pcxenc.c 2026-11-10 15:39:28 @@ -34,12 +34,21 @@ static const uint32_t monoblack_pal[16] = { 0x000000, 0xFFFFFF }; +static uint8_t *put_run(uint8_t *dst, uint8_t value, int count) +{ + if (count != 1 || value >= 0xC0) + *dst++ = 0xC0 | count; + *dst++ = value; + return dst; +} + /** * PCX run-length encoder * @param dst output buffer * @param dst_size size of output buffer * @param src input buffer - * @param src_plane_size size of one plane of input buffer in bytes + * @param src_plane_size size of one plane of input buffer in bytes, an odd + * size is padded with a zero byte * @param nplanes number of planes in input buffer * @return number of bytes written to dst or -1 on error * @bug will not work for nplanes != 1 && bpp != 8 @@ -49,36 +58,35 @@ { int p; const uint8_t *dst_start = dst; + int pad = src_plane_size & 1; // check worst-case upper bound on dst_size - if (dst_size < 2LL * src_plane_size * nplanes || src_plane_size <= 0) + if (dst_size < 2LL * (src_plane_size + pad) * nplanes || src_plane_size <= 0) return AVERROR(EINVAL); for (p = 0; p < nplanes; p++) { - int count = 1; + int count = 1, i, zero_pad = pad; const uint8_t *src_plane = src + p; - const uint8_t *src_plane_end = src_plane + src_plane_size * nplanes; uint8_t prev = *src_plane; - src_plane += nplanes; - for (; ; src_plane += nplanes) { - if (src_plane < src_plane_end && *src_plane == prev && count < 0x3F) { - // current byte is same as prev - ++count; - } else { - // output prev * count - if (count != 1 || prev >= 0xC0) - *dst++ = 0xC0 | count; - *dst++ = prev; + for (i = 1; i < src_plane_size; i++) { + uint8_t cur = src_plane[i * nplanes]; - if (src_plane == src_plane_end) - break; - - // start new run - count = 1; - prev = *src_plane; + if (cur == prev && count < 0x3F) { + ++count; + continue; } + dst = put_run(dst, prev, count); + count = 1; + prev = cur; } + if (zero_pad && !prev && count < 0x3F) { + count++; + zero_pad = 0; + } + dst = put_run(dst, prev, count); + if (zero_pad) + *dst++ = 0; } return dst - dst_start; @@ -90,7 +98,7 @@ const uint8_t *buf_end; uint8_t *buf; - int bpp, nplanes, i, y, line_bytes, written, ret, max_pkt_size, sw, sh; + int bpp, nplanes, i, y, line_bytes, src_plane_size, written, ret, max_pkt_size, sw, sh; const uint32_t *pal = NULL; uint32_t palette256[256]; const uint8_t *src; @@ -130,8 +138,8 @@ return AVERROR(EINVAL); } - line_bytes = (avctx->width * bpp + 7) >> 3; - line_bytes = (line_bytes + 1) & ~1; + src_plane_size = (avctx->width * bpp + 7) >> 3; + line_bytes = (src_plane_size + 1) & ~1; max_pkt_size = 128 + avctx->height * 2 * line_bytes * nplanes + (pal ? 256*3 + 1 : 0); if ((ret = ff_alloc_packet(avctx, pkt, max_pkt_size)) < 0) @@ -167,7 +175,7 @@ for (y = 0; y < avctx->height; y++) { if ((written = pcx_rle_encode(buf, buf_end - buf, - src, line_bytes, nplanes)) < 0) { + src, src_plane_size, nplanes)) < 0) { av_log(avctx, AV_LOG_ERROR, "buffer too small\n"); return AVERROR_BUG; } diff -ruN a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c --- a/libavcodec/proresenc_anatoliy.c 2026-08-03 18:14:47 +++ b/libavcodec/proresenc_anatoliy.c 2026-11-10 15:39:52 @@ -733,7 +733,7 @@ uint8_t *buf; int compress_frame_size, pic_size, ret, is_top_field_first = 0; uint8_t frame_flags; - int frame_size = FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + FF_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit + int64_t frame_size = (int64_t)FFALIGN(avctx->width, 16) * FFALIGN(avctx->height, 16)*16 + 500 + FF_INPUT_BUFFER_MIN_SIZE; //FIXME choose tighter limit if ((ret = ff_alloc_packet(avctx, pkt, frame_size + FF_INPUT_BUFFER_MIN_SIZE)) < 0) diff -ruN a/libavcodec/proresenc_kostya_common.c b/libavcodec/proresenc_kostya_common.c --- a/libavcodec/proresenc_kostya_common.c 2026-08-03 18:14:47 +++ b/libavcodec/proresenc_kostya_common.c 2026-11-10 15:39:52 @@ -24,6 +24,7 @@ #include "libavutil/pixdesc.h" #include "avcodec.h" #include "bytestream.h" +#include "encode.h" #include "proresdata.h" #include #include "proresenc_kostya_common.h" @@ -283,19 +284,27 @@ ctx->bits_per_mb += ls_chroma * 4; } - ctx->frame_size_upper_bound = (ctx->pictures_per_frame * + int64_t frame_size_upper_bound = (int64_t)(ctx->pictures_per_frame * ctx->slices_per_picture + 1) * (2 + 2 * ctx->num_planes + (mps * ctx->bits_per_mb) / 8) + 200; + ctx->slice_size_upper_bound = mps * (ctx->chroma_factor == CFACTOR_Y444 ? 768 : 512) * 8; if (ctx->alpha_bits) { // The alpha plane is run-coded and might exceed the bit budget. - ctx->frame_size_upper_bound += (ctx->pictures_per_frame * - ctx->slices_per_picture + 1) * - /* num pixels per slice */ (ctx->mbs_per_slice * 256 * - /* bits per pixel */ (1 + ctx->alpha_bits + 1) + 7 >> 3); + int alpha_slice_size = /* num pixels per slice */ mps * 256 * + /* bits per pixel */ (1 + ctx->alpha_bits + 1) + 7 >> 3; + frame_size_upper_bound += (int64_t)(ctx->pictures_per_frame * + ctx->slices_per_picture + 1) * alpha_slice_size; + ctx->slice_size_upper_bound += alpha_slice_size; } + + if (frame_size_upper_bound + ctx->slice_size_upper_bound + FF_INPUT_BUFFER_MIN_SIZE > INT_MAX) { + av_log(avctx, AV_LOG_ERROR, "Frame too large to encode\n"); + return AVERROR(EINVAL); + } + ctx->frame_size_upper_bound = frame_size_upper_bound; avctx->codec_tag = ctx->profile_info->tag; avctx->profile = ctx->profile; diff -ruN a/libavcodec/proresenc_kostya_common.h b/libavcodec/proresenc_kostya_common.h --- a/libavcodec/proresenc_kostya_common.h 2026-08-03 18:14:47 +++ b/libavcodec/proresenc_kostya_common.h 2026-11-10 15:39:52 @@ -112,6 +112,7 @@ int quant_sel; int frame_size_upper_bound; + int slice_size_upper_bound; int profile; const struct prores_profile *profile_info; diff -ruN a/libavcodec/psd.c b/libavcodec/psd.c --- a/libavcodec/psd.c 2026-08-03 18:14:47 +++ b/libavcodec/psd.c 2026-11-10 15:39:28 @@ -444,6 +444,8 @@ } s->uncompressed_size = s->line_size * s->height * s->channel_count; + if (s->uncompressed_size > INT_MAX) + return AVERROR_INVALIDDATA; /* decode picture if need */ if (s->compression == PSD_RLE) { @@ -467,8 +469,10 @@ ptr_data = s->gb.buffer; } - if ((ret = ff_get_buffer(avctx, picture, 0)) < 0) + if ((ret = ff_get_buffer(avctx, picture, 0)) < 0) { + av_freep(&s->tmp); return ret; + } /* Store data */ if ((avctx->pix_fmt == AV_PIX_FMT_YA8)||(avctx->pix_fmt == AV_PIX_FMT_YA16BE)){/* Interleaved */ diff -ruN a/libavcodec/riscv/llvidencdsp_rvv.S b/libavcodec/riscv/llvidencdsp_rvv.S --- a/libavcodec/riscv/llvidencdsp_rvv.S 2026-08-03 18:14:47 +++ b/libavcodec/riscv/llvidencdsp_rvv.S 2026-11-10 15:39:52 @@ -22,6 +22,7 @@ func ff_llvidenc_diff_bytes_rvv, zve32x lpad 0 + blez a3, 2f 1: vsetvli t0, a3, e8, m8, ta, ma vle8.v v0, (a1) @@ -33,7 +34,7 @@ vse8.v v8, (a0) add a0, t0, a0 bnez a3, 1b - +2: ret endfunc diff -ruN a/libavcodec/sgienc.c b/libavcodec/sgienc.c --- a/libavcodec/sgienc.c 2026-08-03 18:14:47 +++ b/libavcodec/sgienc.c 2026-11-10 15:39:28 @@ -100,8 +100,8 @@ PutByteContext pbc; uint8_t *encode_buf; int x, y, z, length, tablesize, ret, i; - unsigned int width, height, depth, dimension; - unsigned int bytes_per_channel, pixmax, put_be; + int width, height, depth, dimension; + int bytes_per_channel, pixmax, put_be; width = avctx->width; height = avctx->height; @@ -160,7 +160,7 @@ else // assume sgi_rle_encode() produces at most 2x size of input length += tablesize * 2 + depth * height * (2 * width + 1); - if ((ret = ff_alloc_packet(avctx, pkt, bytes_per_channel * length)) < 0) + if ((ret = ff_alloc_packet(avctx, pkt, (int64_t)bytes_per_channel * length)) < 0) return ret; bytestream2_init_writer(&pbc, pkt->data, pkt->size); @@ -205,7 +205,7 @@ return AVERROR(ENOMEM); for (z = 0; z < depth; z++) { - const uint8_t *in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel; + const uint8_t *in_buf = p->data[0] + (ptrdiff_t)p->linesize[0] * (height - 1) + z * bytes_per_channel; for (y = 0; y < height; y++) { bytestream2_put_be32(&taboff_pcb, bytestream2_tell_p(&pbc)); @@ -236,7 +236,7 @@ av_free(encode_buf); } else { for (z = 0; z < depth; z++) { - const uint8_t *in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel; + const uint8_t *in_buf = p->data[0] + (ptrdiff_t)p->linesize[0] * (height - 1) + z * bytes_per_channel; for (y = 0; y < height; y++) { for (x = 0; x < width * depth; x += depth) diff -ruN a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c --- a/libavcodec/v4l2_buffers.c 2026-08-03 18:14:47 +++ b/libavcodec/v4l2_buffers.c 2026-11-10 15:39:52 @@ -268,10 +268,10 @@ in->context_ref = av_refstruct_ref(s->self_ref); in->context_refcount = 1; + atomic_fetch_add_explicit(&s->refcount, 1, memory_order_relaxed); } in->status = V4L2BUF_RET_USER; - atomic_fetch_add_explicit(&s->refcount, 1, memory_order_relaxed); return 0; } @@ -360,9 +360,44 @@ return 0; } +static int v4l2_buffer_swframe_to_planes(const AVFrame *frame, V4L2Buffer *out) +{ + const struct v4l2_pix_format_mplane *pix_mp = &out->context->format.fmt.pix_mp; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); + int height = pix_mp->height; + int bytewidths[4]; + int ret; + + if (!desc || !V4L2_TYPE_IS_MULTIPLANAR(out->buf.type) || + out->num_planes > av_pix_fmt_count_planes(frame->format) || + frame->width > pix_mp->width || frame->height > height) + return AVERROR(EINVAL); + + ret = av_image_fill_linesizes(bytewidths, frame->format, frame->width); + if (ret < 0) + return ret; + + for (int i = 0; i < out->num_planes; i++) { + int shift = i == 1 || i == 2 ? desc->log2_chroma_h : 0; + size_t stride = pix_mp->plane_fmt[i].bytesperline; + size_t size = stride * AV_CEIL_RSHIFT(height, shift); + + if (!frame->data[i] || stride < bytewidths[i] || + size > out->plane_info[i].length) + return AVERROR(EINVAL); + + av_image_copy_plane(out->plane_info[i].mm_addr, stride, + frame->data[i], frame->linesize[i], bytewidths[i], + AV_CEIL_RSHIFT(frame->height, shift)); + out->planes[i].bytesused = size; + out->planes[i].length = out->plane_info[i].length; + } + + return 0; +} + static int v4l2_buffer_swframe_to_buf(const AVFrame *frame, V4L2Buffer *out) { - int i, ret; struct v4l2_format fmt = out->context->format; int pixel_format = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ? fmt.fmt.pix_mp.pixelformat : fmt.fmt.pix.pixelformat; @@ -416,13 +451,7 @@ return 0; } - for (i = 0; i < out->num_planes; i++) { - ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, frame->buf[i]->size, 0); - if (ret) - return ret; - } - - return 0; + return v4l2_buffer_swframe_to_planes(frame, out); } /****************************************************************************** diff -ruN a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c --- a/libavcodec/vvc/ps.c 2026-09-17 22:29:35 +++ b/libavcodec/vvc/ps.c 2026-11-10 15:39:52 @@ -927,7 +927,7 @@ return sps->sps_sbtmvp_enabled_flag && ph->ph_temporal_mvp_enabled_flag; } -static int ph_vb_pos(uint16_t *vbs, uint8_t *num_vbs, const uint16_t *pos_minus_1, const uint8_t num_pos, uint16_t max, const int ctb_size_y) +static int ph_vb_pos(uint16_t *vbs, uint8_t *num_vbs, const uint16_t *pos_minus_1, const uint8_t num_pos, int max, const int ctb_size_y) { max = FF_CEIL_RSHIFT(max, 3) - 2; for (int i = 0; i < num_pos; i++) { diff -ruN a/libavcodec/xwdenc.c b/libavcodec/xwdenc.c --- a/libavcodec/xwdenc.c 2026-08-03 18:14:47 +++ b/libavcodec/xwdenc.c 2026-11-10 15:39:28 @@ -39,7 +39,7 @@ uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; uint32_t rgb[3] = { 0 }, bitorder = 0; uint32_t header_size; - int i, out_size, ret; + int i, out_size, ret, row_bytes; const uint8_t *ptr; uint8_t *buf; uint32_t pal[256]; @@ -144,6 +144,7 @@ return AVERROR(EINVAL); } + row_bytes = (bpp * avctx->width + 7) / 8; lsize = FFALIGN(bpp * avctx->width, bpad) / 8; header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE; out_size = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize; @@ -204,7 +205,9 @@ ptr = p->data[0]; for (i = 0; i < avctx->height; i++) { - bytestream_put_buffer(&buf, ptr, lsize); + bytestream_put_buffer(&buf, ptr, row_bytes); + memset(buf, 0, lsize - row_bytes); + buf += lsize - row_bytes; ptr += p->linesize[0]; } diff -ruN a/libavfilter/vf_median.c b/libavfilter/vf_median.c --- a/libavfilter/vf_median.c 2026-08-03 18:14:47 +++ b/libavfilter/vf_median.c 2026-11-10 15:39:52 @@ -143,6 +143,11 @@ s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radiusV + 1), ff_filter_get_nb_threads(inlink->dst))); s->bins = 1 << ((s->depth + 1) / 2); + if (inlink->w > INT_MAX / (s->bins * s->bins)) { + av_log(inlink->dst, AV_LOG_ERROR, "Width %d is too large for depth %d\n", + inlink->w, s->depth); + return AVERROR(EINVAL); + } s->fine_size = s->bins * s->bins * inlink->w; s->coarse_size = s->bins * inlink->w; s->coarse = av_calloc(s->nb_threads, sizeof(*s->coarse)); diff -ruN a/libavfilter/vf_tonemap.c b/libavfilter/vf_tonemap.c --- a/libavfilter/vf_tonemap.c 2026-08-03 18:14:47 +++ b/libavfilter/vf_tonemap.c 2026-11-10 15:39:52 @@ -263,7 +263,7 @@ if (desc->flags & AV_PIX_FMT_FLAG_ALPHA && odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { av_image_copy_plane(out->data[3], out->linesize[3], in->data[3], in->linesize[3], - out->linesize[3], outlink->h); + out->width * odesc->comp[3].step, outlink->h); } else if (odesc->flags & AV_PIX_FMT_FLAG_ALPHA) { for (y = 0; y < out->height; y++) { for (x = 0; x < out->width; x++) { diff -ruN a/libavutil/frame.c b/libavutil/frame.c --- a/libavutil/frame.c 2026-08-03 18:14:48 +++ b/libavutil/frame.c 2026-11-10 15:39:52 @@ -727,7 +727,7 @@ av_frame_side_data_remove(&frame->side_data, &frame->nb_side_data, type); } -static int calc_cropping_offsets(size_t offsets[4], const AVFrame *frame, +static int calc_cropping_offsets(ptrdiff_t offsets[4], const AVFrame *frame, const AVPixFmtDescriptor *desc) { for (int i = 0; frame->data[i]; i++) { @@ -750,8 +750,8 @@ if (!comp) return AVERROR_BUG; - offsets[i] = (frame->crop_top >> shift_y) * frame->linesize[i] + - (frame->crop_left >> shift_x) * comp->step; + offsets[i] = (ptrdiff_t)(frame->crop_top >> shift_y) * frame->linesize[i] + + (ptrdiff_t)(frame->crop_left >> shift_x) * comp->step; } return 0; @@ -760,7 +760,7 @@ int av_frame_apply_cropping(AVFrame *frame, int flags) { const AVPixFmtDescriptor *desc; - size_t offsets[4]; + ptrdiff_t offsets[4]; int ret; if (!(frame->width > 0 && frame->height > 0))