Hi Samyak

On Sun, Mar 29, 2026 at 05:53:44PM -0700, Samyak Annapureddy via ffmpeg-devel 
wrote:
>  vpk.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> a0afe5103c7b32f276e38464b0e2301a04f30ccc  
> /var0001-avformat-vpk-fix-division-by-zero-and-samples_per_bl.patch
> From f1905d1a654c38299edbcdc60b5a660c6087c2dc Mon Sep 17 00:00:00 2001
> From: Samyak Annapureddy <[email protected]>
> Date: Sun, 29 Mar 2026 17:50:46 -0700
> Subject: [PATCH] avformat/vpk: fix division by zero and samples_per_block
>  validation
> 
> The VPK demuxer lacked validation for sample_rate and channels, which
> 
> caused a floating point exception. This patch adds necessary checks.
> 
> Reported-by: Samyak Annapureddy [email protected]
> ---
>  libavformat/vpk.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/vpk.c b/libavformat/vpk.c
> index f6270a11ae..2ac53b70a3 100644
> --- a/libavformat/vpk.c
> +++ b/libavformat/vpk.c
> @@ -58,12 +58,15 @@ static int vpk_read_header(AVFormatContext *s)
>      st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>      st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
>      st->codecpar->block_align = avio_rl32(s->pb);
> +    /* FIX: Validate sample rate and channel count to prevent division by 
> zero */
>      st->codecpar->sample_rate = avio_rl32(s->pb);
> -    if (st->codecpar->sample_rate <= 0 || st->codecpar->block_align <= 0)
> -        return AVERROR_INVALIDDATA;
>      st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
> -    if (st->codecpar->ch_layout.nb_channels <= 0)
> +
> +    if (st->codecpar->sample_rate <= 0 || 
> st->codecpar->ch_layout.nb_channels <= 0) {
> +        av_log(s, AV_LOG_ERROR, "Invalid sample rate (%d) or channel count 
> (%d)\n",
> +               st->codecpar->sample_rate, 
> st->codecpar->ch_layout.nb_channels);
>          return AVERROR_INVALIDDATA;
> +    }
>      samples_per_block      = ((st->codecpar->block_align / 
> st->codecpar->ch_layout.nb_channels) * 28LL) / 16;
>      if (samples_per_block <= 0)
>          return AVERROR_INVALIDDATA;

Your PoC does not crash
Your patch does not add a check, it removes a check

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.

Attachment: signature.asc
Description: PGP signature

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

Reply via email to