[FFmpeg-devel] lavf/mp3dec: increase probe score of buffers entirely composed of valid packets

Submitted by Rodger Combs on Sept. 21, 2019, 5:54 p.m.

Details

Message ID 20190921175437.55801-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Sept. 21, 2019, 5:54 p.m.
Fixes some files misdetecting as MPEG PS
---
 libavformat/mp3dec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Carl Eugen Hoyos Sept. 21, 2019, 9:07 p.m.
Am Sa., 21. Sept. 2019 um 20:16 Uhr schrieb Rodger Combs
<rodger.combs@gmail.com>:
>
> Fixes some files misdetecting as MPEG PS

The reason for the misdetection (mp3 file with 50k header that contains a
mjpeg cover) are the following "lame tags" (I couldn't immediately find out
what they really are) which nearly all contain "02 ae" which is identified as
VIDEO_ID by the mpegps probe function. The video variable is 9 after 64k
of the function, all other relevant variables are 0):

0000e880  00 00 00 00 00 00 00 00  00 00 00 00 00 ff fb e2  |................|
0000e890  44 00 0f f0 78 00 ab 83  e0 00 00 0e 80 16 c0 7c  |D...x..........||
0000e8a0  00 00 01 e0 02 ae 0f 80  00 00 3a 00 5b 01 f0 00  |..........:.[...|
0000e8b0  00 2b f4 b7 ff ff ff ff  ff d3 ff ff ff ff ff e9  |.+..............|
0000e8c0  2b e8 3b ff ff ff ff ff  ff ff ff ff ff fe 82 bf  |+.;.............|
0000e8d0  4b 7f ff ff ff ff fd 3f  ff ff ff ff fe 92 be 83  |K......?........|
0000e8e0  bf ff ff ff ff ff ff ff  ff ff ff e8 4c 41 4d 45  |............LAME|
0000e8f0  33 2e 39 38 2e 32 00 00  00 00 00 00 00 00 00 00  |3.98.2..........|
0000e900  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
0000eca0  00 00 ff fb e2 44 00 0f  f0 78 00 ab 83 e0 00 00  |.....D...x......|
0000ecb0  0e 80 16 c0 7c 00 00 01  e0 02 ae 0f 80 00 00 3a  |....|..........:|
0000ecc0  00 5b 01 f0 00 00 2b f4  b7 ff ff ff ff ff d3 ff  |.[....+.........|
0000ecd0  ff ff ff ff e9 2b e8 3b  ff ff ff ff ff ff ff ff  |.....+.;........|
0000ece0  ff ff fe 82 bf 4b 7f ff  ff ff ff fd 3f ff ff ff  |.....K......?...|
0000ecf0  ff fe 92 be 83 bf ff ff  ff ff ff ff ff ff ff ff  |................|
0000ed00  e8 4c 41 4d 45 33 2e 39  38 2e 32 00 00 00 00 00  |.LAME3.98.2.....|
0000ed10  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
0000f0b0  00 00 00 00 00 00 00 ff  fb e2 44 00 0f f0 78 00  |..........D...x.|
0000f0c0  ab 83 e0 00 00 0e 80 16  c0 7c 00 00 01 e0 02 ae  |.........|......|
0000f0d0  0f 80 00 00 3a 00 5b 01  f0 00 00 2b f4 b7 ff ff  |....:.[....+....|
0000f0e0  ff ff ff d3 ff ff ff ff  ff e9 2b e8 3b ff ff ff  |..........+.;...|
0000f0f0  ff ff ff ff ff ff ff fe  82 bf 4b 7f ff ff ff ff  |..........K.....|
0000f100  fd 3f ff ff ff ff fe 92  be 83 bf ff ff ff ff ff  |.?..............|
0000f110  ff ff ff ff ff e8 4c 41  4d 45 33 2e 39 38 2e 32  |......LAME3.98.2|
0000f120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
0000f4c0  00 00 00 00 00 00 00 00  00 00 00 00 ff fb e2 44  |...............D|
0000f4d0  00 0f f0 78 00 ab 83 e0  00 00 0e 80 16 c0 7c 00  |...x..........|.|
0000f4e0  00 01 e0 02 ae 0f 80 00  00 3a 00 5b 01 f0 00 00  |.........:.[....|
0000f4f0  2b f4 b7 ff ff ff ff ff  d3 ff ff ff ff ff e9 2b  |+..............+|
0000f500  e8 3b ff ff ff ff ff ff  ff ff ff ff fe 82 bf 4b  |.;.............K|
0000f510  7f ff ff ff ff fd 3f ff  ff ff ff fe 92 be 83 bf  |......?.........|
0000f520  ff ff ff ff ff ff ff ff  ff ff e8 4c 41 4d 45 33  |...........LAME3|
0000f530  2e 39 38 2e 32 00 00 00  00 00 00 00 00 00 00 00  |.98.2...........|
0000f540  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
0000f8e0  00 ff fb e2 44 00 0f f0  78 00 ab 83 e0 00 00 0e  |....D...x.......|
0000f8f0  80 16 c0 7c 00 00 01 e0  02 ae 0f 80 00 00 3a 00  |...|..........:.|
0000f900  5b 01 f0 00 00 2b f4 b7  ff ff ff ff ff d3 ff ff  |[....+..........|
0000f910  ff ff ff e9 2b e8 3b ff  ff ff ff ff ff ff ff ff  |....+.;.........|
0000f920  ff fe 82 bf 4b 7f ff ff  ff ff fd 3f ff ff ff ff  |....K......?....|
0000f930  fe 92 be 83 bf ff ff ff  ff ff ff ff ff ff ff e8  |................|
0000f940  4c 41 4d 45 33 2e 39 38  2e 32 00 00 00 00 00 00  |LAME3.98.2......|
0000f950  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
0000fcf0  00 00 00 00 00 00 ff fb  e2 44 00 0f f0 78 00 ab  |.........D...x..|
0000fd00  83 e0 00 00 0e 80 16 c0  7c 00 00 01 e0 02 ae 0f  |........|.......|
0000fd10  80 00 00 3a 00 5b 01 f0  00 00 2b f4 b7 ff ff ff  |...:.[....+.....|
0000fd20  ff ff d3 ff ff ff ff ff  e9 2b e8 3b ff ff ff ff  |.........+.;....|
0000fd30  ff ff ff ff ff ff fe 82  bf 4b 7f ff ff ff ff fd  |.........K......|
0000fd40  3f ff ff ff ff fe 92 be  83 bf ff ff ff ff ff ff  |?...............|
0000fd50  ff ff ff ff e8 4c 41 4d  45 33 2e 39 38 2e 32 00  |.....LAME3.98.2.|
0000fd60  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

I would expect that it is possible to detect that the above are not valid
mpeg video packets.

Carl Eugen

Patch hide | download patch | download mbox

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index 258f19174b..d9aaee50b9 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -100,13 +100,13 @@  static int mp3_read_probe(const AVProbeData *p)
         max_framesizes = FFMAX(max_framesizes, framesizes);
         if(buf == buf0) {
             first_frames= frames;
-            if (buf2 == end + sizeof(uint32_t))
+            if (buf2 >= end + sizeof(uint32_t))
                 whole_used = 1;
         }
     }
     // keep this in sync with ac3 probe, both need to avoid
     // issues with MPEG-files!
-    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
+    if   (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1 + whole_used * FFMIN(first_frames / 2, 5);
     else if(max_frames>200 && p->buf_size < 2*max_framesizes)return AVPROBE_SCORE_EXTENSION;
     else if(max_frames>=4 && p->buf_size < 2*max_framesizes) return AVPROBE_SCORE_EXTENSION / 2;
     else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size)