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

samples_per_block is read from the HEAD chunk without validation; any seek into 
a crafted file divides by it in read_seek() and aborts the process (SIGFPE). 
Reject SPB==0 at read_header(): no valid file has it, since every block would 
then hold zero samples. Full analysis in the commit message; 342-byte repro 
sample and a positive control (SPB=100, decodes to PCM) available on request. 
make fate passes.


>From f6b2f32f348651f4884a385429682139c16c5b3a Mon Sep 17 00:00:00 2001
From: Richard Desmarais <[email protected]>
Date: Thu, 12 Nov 2026 00:29:14 -0500
Subject: [PATCH] avformat/brstm: reject a zero samples per block value

samples_per_block is read from the HEAD chunk and never validated. A
crafted BRSTM/BFSTM with samples_per_block == 0 opens fine, but any seek
divides by it in read_seek(), crashing the process with SIGFPE (integer
division by zero) on non-sanitized builds:

    timestamp /= b->samples_per_block;

Reproduce with the attached 342-byte sample (PCM16BE planar, SPB=0):
    ffmpeg -ss 1 -f brstm -i poc.bstm -f null -
before: "runtime error: division by zero" (UBSan) / SIGFPE;
after: "zero samples per block", AVERROR_INVALIDDATA.

No valid file has samples_per_block == 0: every block would contain zero
samples, so rejecting at read_header() is safe. Positive control (same
file, SPB=100) still decodes to PCM.

Signed-off-by: Richard Desmarais <[email protected]>
---
 libavformat/brstm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/brstm.c b/libavformat/brstm.c
index 3fe19fff721..e67ddb2d016 100644
--- a/libavformat/brstm.c
+++ b/libavformat/brstm.c
@@ -253,6 +253,10 @@ static int read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
 
     b->samples_per_block = read32(s);
+    if (!b->samples_per_block) {
+        av_log(s, AV_LOG_ERROR, "zero samples per block\n");
+        return AVERROR_INVALIDDATA;
+    }
     b->last_block_used_bytes = read32(s);
     b->last_block_samples = read32(s);
     b->last_block_size = read32(s);
-- 
2.54.0

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

Reply via email to