PR #25193 opened by Marti2203
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25193
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25193.patch

For the high bit depth GBR(A) formats, `ff_ffv1_encode_setup_plane_info()` 
copies a user supplied `bits_per_raw_sample` without the range check done for 
the YUV/gray formats, so a value below 8 reaches 
`av_assert0(s->bits_per_raw_sample >= 8)` and aborts:

```
ffmpeg -f lavfi -i testsrc2=s=64x48:d=0.04,format=gbrp10le -c:v ffv1 
-bits_per_raw_sample 7 -f null -
Assertion s->bits_per_raw_sample >= 8 failed at src/libavcodec/ffv1enc.c:1000
Aborted (core dumped)
```

The same value with e.g. `yuv420p10le` or `gray10le` is rejected with 
"bits_per_raw_sample invalid".

With the patch values below 8 are rejected the same way for the GBR(A) formats 
(checked gbrp10le, gbrap12le, gbrpf32le with 1 and 7); 8 and above behave as 
before, default encodes of gbrp, gbrp10le and gbrap12le are bit-identical, and 
`fate-vsynth1-ffv1`, `fate-vsynth1-ffv1-v3-rgb48`, `fate-vsynth1-ffv1-v3-bgr0` 
and `fate-vsynth2-ffv1` pass. Only values below 8 are rejected, as that is what 
the assertion requires; gbrp10le with 8 currently encodes fine and is left 
alone.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified 
manually.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



From c15adb3a95c764373579ee3578148ceb89f2ba0c Mon Sep 17 00:00:00 2001
From: Martin Mirchev <[email protected]>
Date: Sun, 18 Oct 2026 22:11:57 +0800
Subject: [PATCH] avcodec/ffv1enc: reject bits_per_raw_sample below 8 for GBR
 formats

For the high bit depth GBR(A) formats a user supplied bits_per_raw_sample
was copied without the check done for the YUV formats, so e.g.
-pix_fmt gbrp10le -bits_per_raw_sample 7 aborted on
av_assert0(s->bits_per_raw_sample >= 8). Fail with an error instead.

Signed-off-by: Martin Mirchev <[email protected]>
---
 libavcodec/ffv1enc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 1d18f10f05..5bd22dd920 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -981,6 +981,10 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext 
*avctx,
             s->bits_per_raw_sample = 32;
         else if (!s->bits_per_raw_sample)
             s->bits_per_raw_sample = avctx->bits_per_raw_sample;
+        if (s->bits_per_raw_sample < 8) {
+            av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample invalid\n");
+            return AVERROR_INVALIDDATA;
+        }
         s->transparency = !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA);
         s->colorspace = 1;
         s->chroma_planes = 1;
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to