This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 27f612b306eb04f81138173f705df9a9b055b01d Author: Michael Niedermayer <[email protected]> AuthorDate: Sat Oct 31 05:17:46 2026 +0100 Commit: michaelni <[email protected]> CommitDate: Thu Nov 5 23:01:14 2026 +0000 avcodec/flicvideo: bound pixel writes at both ends of the frame storage Fixes: out of array write Fixes: GGsIHTeUwf0U Fixes: AISLE-2026-0150-00642 Out of array write Replicated through API with ASAN Found-by: Joshua Rogers (AISLE) --- libavcodec/flicvideo.c | 56 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c index 21f861dd3a..d00ff9610d 100644 --- a/libavcodec/flicvideo.c +++ b/libavcodec/flicvideo.c @@ -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 @@ static int flic_decode_frame_1BPP(AVCodecContext *avctx, 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 @@ static int flic_decode_frame_1BPP(AVCodecContext *avctx, 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 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, 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 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, 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 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, "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 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, 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 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, 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 */ @@ -930,7 +939,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, 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; @@ -997,7 +1006,7 @@ static int flic_decode_frame_24BPP(AVCodecContext *avctx, unsigned int chunk_size; int chunk_type; - int i, j, ret, direction; + int i, j, ret; int lines; int compressed_lines; @@ -1008,16 +1017,15 @@ static int flic_decode_frame_24BPP(AVCodecContext *avctx, 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 */ @@ -1216,7 +1224,7 @@ static int flic_decode_frame_24BPP(AVCodecContext *avctx, "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); -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
