diff mbox series

[FFmpeg-devel,1/1] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits

Message ID 20240311140128.1730332-2-nicolas.gaullier@cji.paris
State New
Headers show
Series avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Nicolas Gaullier March 11, 2024, 2:01 p.m. UTC
Mantissas are the last data in the channel subsegment and it appears it
is sometimes missing a very few bits for the parsing to complete.
This must not be confused with data corruption.
In standard conditions with certified products, it has been observed
that the occurence of this issue is pretty steady and about once every 2
hours. The truncation is at about 950 out of the 1024 values (923 is the
minimum I have seen so far).
The current code raises a severe 'Read past end' error and all data is
lost resulting in 20ms(@25fps) of silence for the affected channel.
This patch introduces a tolerance: if 800 out of the 1024 mantissas have
been parsed, a simple warning is raised and the data is preserved.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier@cji.paris>
---
 libavcodec/dolby_e.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Nicolas Gaullier March 26, 2024, 4:16 p.m. UTC | #1
>De : Nicolas Gaullier <nicolas.gaullier@cji.paris> 
>Envoyé : lundi 11 mars 2024 15:01
>
>Mantissas are the last data in the channel subsegment and it appears it is sometimes missing a very few bits for the parsing to complete.
>This must not be confused with data corruption.
>In standard conditions with certified products, it has been observed that the occurence of this issue is pretty steady and about once every 2 hours. The truncation is at about 950 out of the 1024 values (923 is the minimum I have seen so far).
>The current code raises a severe 'Read past end' error and all data is lost resulting in 20ms(@25fps) of silence for the affected channel.
>This patch introduces a tolerance: if 800 out of the 1024 mantissas have been parsed, a simple warning is raised and the data is preserved.

Ping ?
still applies
last posted here: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=11090
Samples (source/before patch/after patch) here: https://0x0.st/oOvv.zip

Nicolas
diff mbox series

Patch

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 9c3f6006c2..1f8442e2e9 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -845,6 +845,7 @@  static int parse_indices(DBEContext *s, DBEChannel *c)
     return 0;
 }
 
+#define MIN_MANTISSAS 800
 static int parse_mantissas(DBEContext *s, DBEChannel *c)
 {
     DBEGroup *g;
@@ -885,6 +886,13 @@  static int parse_mantissas(DBEContext *s, DBEChannel *c)
                     }
                 }
             } else {
+                if (i == c->nb_groups - 1
+                    && count * size1 > get_bits_left(&s->gb)
+                    && get_bits_left(&s->gb) >= 0
+                    && (int)(mnt - c->mantissas) >= MIN_MANTISSAS) {
+                    av_log(s->avctx, AV_LOG_WARNING, "Truncated mantissas @%d, highest frequencies not recoverable\n", (int)(mnt - c->mantissas));
+                    break;
+                }
                 for (k = 0; k < count; k++)
                     mnt[k] = get_sbits(&s->gb, size1) * scale;
             }