From: damitha via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: damitha <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] libavcodec/aac: add clamping for escape coeff (PR #20376)
Message-ID: <175660903942.25.8061148897280811546@463a07221176> (raw)
PR #20376 opened by damitha
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20376
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20376.patch
Have noticed that escape coefficient on spectral data can be less than 16 on rare occasions.
The failure reproduces deterministically on macOS (ARM) and x86-64, at the same frame for the same source.
Example
| field | Header |
|---------|---------|
| fabsf(in[i+j]) | 275295.156 |
| Q | 0.00014516688 |
| ROUNDING | 0.105400003 |
| coef_float | 15.99999932 |
| coef_int | 15 |
The casting to int ends up being 15. This breaks the `put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);` to be noop.
Then `put_sbits(pb, len, coef);` becomes 000. This cause the decoder to have over read here. Eventually the fails at the sections_data() read on the next channel. (At least on the samples I have noticed).
So forcing the coefficient minimum to be 16.
Issue Link: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20373
>From 6d4dbf148b8f272c95669636e0a6b10f1797552e Mon Sep 17 00:00:00 2001
From: damitha <damitha.gunawardena@gmail.com>
Date: Sun, 31 Aug 2025 06:50:48 +1000
Subject: [PATCH] add clamping for escpase coeff
---
libavcodec/aaccoder.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 96915c9731..7f1c4cdcc1 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -173,7 +173,7 @@ static av_always_inline float quantize_and_encode_band_cost_template(
if (BT_ESC) {
for (int j = 0; j < 2; j++) {
if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {
- int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
+ int coef = av_clip(quant(fabsf(in[i+j]), Q, ROUNDING), 16, (1 << 13) - 1);
int len = av_log2(coef);
put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-08-31 2:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175660903942.25.8061148897280811546@463a07221176 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git