Commit f07f02abb8 for ffmpeg
commit f07f02abb864de022b973220e46ef24d203d8bbd
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Mon Oct 12 02:48:35 2026 +0200
avutil/hwcontext_cuda: copy only the bytes of the visible rows
Fixes: out of array access
Fixes: ZqshmgSdN2Q2
Found during triage of the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24595
Out of array read and write Replicated through API with ASAN
Out of array read Replicated through UnModified FFmpeg with a guard page allocator
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 0ee6bb4945..776c321652 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -567,10 +567,16 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
int src_is_nonplanar_cuarray = 0;
int dst_is_nonplanar_cuarray = 0;
+ int bytewidth = av_image_get_linesize(ctx->sw_format, src->width, i);
+ if (bytewidth < 0) {
+ ret = bytewidth;
+ goto fail;
+ }
+
CUDA_MEMCPY2D cpy = {
.srcPitch = src->linesize[i],
.dstPitch = dst->linesize[i],
- .WidthInBytes = FFMIN(src->linesize[i], dst->linesize[i]),
+ .WidthInBytes = bytewidth,
.Height = AV_CEIL_RSHIFT(src->height, ((i == 0 || i == 3) ? 0 : priv->shift_height)),
};