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

The bug was caused by incorrect reading of the step_index field: the original
code read a 16-bit value (including a padding byte) instead of the correct
8-bit step_index as defined by the ADPCM format. This led to distorted audio
or incorrect step calculations when decoding specific ADPCM-encoded files.

Fix by:
1. Reading step_index as an 8-bit unsigned byte via bytestream2_get_byteu()
2. Skipping the subsequent 8-bit padding byte with bytestream2_skip()


>From 6a86fb7d3c0bcd36fa6c4bd2898042e8dd4a779b Mon Sep 17 00:00:00 2001
From: tangsha <[email protected]>
Date: Mon, 1 Dec 2025 16:15:35 +0800
Subject: [PATCH] avcodec/adpcm: Fix step_index decoding by skipping padding
 byte

The bug was caused by incorrect reading of the step_index field: the original
code read a 16-bit value (including a padding byte) instead of the correct
8-bit step_index as defined by the ADPCM format. This led to distorted audio
or incorrect step calculations when decoding specific ADPCM-encoded files.

Fix by:
1. Reading step_index as an 8-bit unsigned byte via bytestream2_get_byteu()
2. Skipping the subsequent 8-bit padding byte with bytestream2_skip()
---
 libavcodec/adpcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 72fbb841a4..df646fa68b 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -1512,7 +1512,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
             ADPCMChannelStatus *cs = &c->status[i];
             cs->predictor = samples_p[i][0] = 
sign_extend(bytestream2_get_le16u(&gb), 16);
 
-            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
+            cs->step_index = bytestream2_get_byteu(&gb);
+            bytestream2_skipu(&gb, 1);
             if (cs->step_index > 88u){
                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
                        i, cs->step_index);
-- 
2.52.0

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

Reply via email to