diff mbox series

[FFmpeg-devel,1/2] aea: make demuxer probing actually work and set title info

Message ID MURndDc--3-2@lynne.ee
State New
Headers show
Series [FFmpeg-devel,1/2] aea: make demuxer probing actually work and set title info
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lynne Feb. 26, 2021, 5:27 a.m. UTC
Someone forgot to add `i` to the loop. 
Also, the format has a 16-char title that we don't currently
check.

Bytestream info from:
https://github.com/dcherednik/atracdenc/blob/master/src/aea.cpp

Patch attached
Subject: [PATCH 1/2] aea: make demuxer probing actually work and set title
 info

Someone forgot to add `i` to the loop.
Also, the format has a 16-char title that we don't currently
check.

Bytestream info from:
https://github.com/dcherednik/atracdenc/blob/master/src/aea.cpp
---
 libavformat/aea.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Andreas Rheinhardt Feb. 26, 2021, 5:57 a.m. UTC | #1
Lynne:
> Someone forgot to add `i` to the loop. 
> Also, the format has a 16-char title that we don't currently
> check.
> 
> Bytestream info from:
> https://github.com/dcherednik/atracdenc/blob/master/src/aea.cpp
> 
> Patch attached
> 
> @@ -61,12 +61,19 @@ static int aea_read_probe(const AVProbeData *p)
>  
>  static int aea_read_header(AVFormatContext *s)
>  {
> +    char title[17] = { 0 };
>      AVStream *st = avformat_new_stream(s, NULL);
>      if (!st)
>          return AVERROR(ENOMEM);
>  
> +    avio_skip(s->pb, 4);
> +
> +    avio_read(s->pb, title, 16);
> +    if (strlen(title) && strlen(title) < 16)
> +        av_dict_set(&s->metadata, "title", title, 0);
> +

You are not checking that you actually read 16 bytes. Maybe use
ffio_read_len for that. If you do, you can modify the check to
if (title[0] && !title[15])
and you also don't need the extra byte in title and can also avoid
initializing it.

>  
> @@ -90,11 +97,8 @@ static int aea_read_header(AVFormatContext *s)
>  static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
>  {
>      int ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
> -
> -    pkt->stream_index = 0;
> -    if (ret <= 0)
> -        return AVERROR(EIO);
> -
> +    if (ret >= 0)
> +        pkt->stream_index = 0;

The check is unnecessary.

>      return ret;
>  }
>  
> --
diff mbox series

Patch

diff --git a/libavformat/aea.c b/libavformat/aea.c
index bdeed64254..7d85840f67 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -46,10 +46,10 @@  static int aea_read_probe(const AVProbeData *p)
          */
         for (i = 2048; i + 211 < p->buf_size; i+= 212) {
             int bsm_s, bsm_e, inb_s, inb_e;
-            bsm_s = p->buf[0];
-            inb_s = p->buf[1];
-            inb_e = p->buf[210];
-            bsm_e = p->buf[211];
+            bsm_s = p->buf[i +   0];
+            inb_s = p->buf[i +   1];
+            inb_e = p->buf[i + 210];
+            bsm_e = p->buf[i + 211];
 
             if (bsm_s != bsm_e || inb_s != inb_e)
                 return 0;
@@ -61,12 +61,19 @@  static int aea_read_probe(const AVProbeData *p)
 
 static int aea_read_header(AVFormatContext *s)
 {
+    char title[17] = { 0 };
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
 
+    avio_skip(s->pb, 4);
+
+    avio_read(s->pb, title, 16);
+    if (strlen(title) && strlen(title) < 16)
+        av_dict_set(&s->metadata, "title", title, 0);
+
     /* Parse the amount of channels and skip to pos 2048(0x800) */
-    avio_skip(s->pb, 264);
+    avio_skip(s->pb, 244);
     st->codecpar->channels = avio_r8(s->pb);
     avio_skip(s->pb, 1783);
 
@@ -90,11 +97,8 @@  static int aea_read_header(AVFormatContext *s)
 static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
-
-    pkt->stream_index = 0;
-    if (ret <= 0)
-        return AVERROR(EIO);
-
+    if (ret >= 0)
+        pkt->stream_index = 0;
     return ret;
 }