[FFmpeg-devel] [PATCH] avformat/tta: only check for header and seek table crc if requested

James Almer jamrial at gmail.com
Thu Feb 5 18:25:27 CET 2015


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/tta.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/libavformat/tta.c b/libavformat/tta.c
index 5789e5b..0c01b7b 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -64,7 +64,8 @@ static int tta_read_header(AVFormatContext *s)
     start_offset = avio_tell(s->pb);
     if (start_offset < 0)
         return start_offset;
-    ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);
+    if (s->error_recognition & AV_EF_CRCCHECK)
+        ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);
     if (avio_rl32(s->pb) != AV_RL32("TTA1"))
         return AVERROR_INVALIDDATA;
 
@@ -83,11 +84,15 @@ static int tta_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;
-    if (crc != avio_rl32(s->pb)) {
-        av_log(s, AV_LOG_ERROR, "Header CRC error\n");
-        return AVERROR_INVALIDDATA;
-    }
+    if (s->error_recognition & AV_EF_CRCCHECK) {
+        crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;
+        if (crc != avio_rl32(s->pb)) {
+            av_log(s, AV_LOG_ERROR, "Header CRC error\n");
+            if (s->error_recognition & AV_EF_EXPLODE)
+                return AVERROR_INVALIDDATA;
+        }
+    } else
+        avio_skip(s->pb, 4); // header crc
 
     c->frame_size      = samplerate * 256 / 245;
     c->last_frame_size = nb_samples % c->frame_size;
@@ -120,7 +125,8 @@ static int tta_read_header(AVFormatContext *s)
     avio_seek(s->pb, start_offset, SEEK_SET);
     avio_read(s->pb, st->codec->extradata, st->codec->extradata_size);
 
-    ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);
+    if (s->error_recognition & AV_EF_CRCCHECK)
+        ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);
     for (i = 0; i < c->totalframes; i++) {
         uint32_t size = avio_rl32(s->pb);
         int r;
@@ -129,11 +135,15 @@ static int tta_read_header(AVFormatContext *s)
             return r;
         framepos += size;
     }
-    crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;
-    if (crc != avio_rl32(s->pb)) {
-        av_log(s, AV_LOG_ERROR, "Seek table CRC error\n");
-        return AVERROR_INVALIDDATA;
-    }
+    if (s->error_recognition & AV_EF_CRCCHECK) {
+        crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;
+        if (crc != avio_rl32(s->pb)) {
+            av_log(s, AV_LOG_ERROR, "Seek table CRC error\n");
+            if (s->error_recognition & AV_EF_EXPLODE)
+                return AVERROR_INVALIDDATA;
+        }
+    } else
+        avio_skip(s->pb, 4); // seektable crc
 
     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codec->codec_id = AV_CODEC_ID_TTA;
-- 
2.2.2



More information about the ffmpeg-devel mailing list