summaryrefslogtreecommitdiff
path: root/libavcodec/tta.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-15 01:38:34 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-02-15 01:52:14 +0100
commitc980be9e3aafad57ec769cbb16c9ad6e640479cb (patch)
treea804c9e2517a2e8ec9e5f22890862cbb226a66da /libavcodec/tta.c
parente7dbfa59f218ece7ec65f7ea0ff2950573dd2267 (diff)
parentdc4e57489fa0f9cf4faf4c85cc405d6db77d84db (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (21 commits) CDXL demuxer and decoder hls: Re-add legacy applehttp name to preserve interface compatibility. hlsproto: Rename the functions and context hlsproto: Encourage users to try the hls demuxer instead of the proto doc: Move the hls protocol section into the right place libavformat: Rename the applehttp protocol to hls hls: Rename the functions and context libavformat: Rename the applehttp demuxer to hls rtpdec: Support H263 in RFC 2190 format rv30: check block type validity ttadec: CRC checking movenc: Support muxing VC1 avconv: Don't split out inline sequence headers when stream copying VC1 rv34: handle size changes during frame multithreading rv40: prevent undefined signed overflow in rv40_loop_filter() rv34: use AVERROR return values in ff_rv34_decode_frame() rv34: use uint16_t for RV34DecContext.deblock_coefs librtmp: Add "lib" prefix to librtmp URLProtocol declarations. movenc: Use defines instead of hardcoded numbers for RTCP types smjpegdec: implement seeking ... Conflicts: Changelog doc/general.texi libavcodec/avcodec.h libavcodec/rv30.c libavcodec/tta.c libavcodec/version.h libavformat/Makefile libavformat/allformats.c libavformat/version.h libswscale/x86/swscale_mmx.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/tta.c')
-rw-r--r--libavcodec/tta.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 3f5ab23b1e..2a4c2e859c 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -32,6 +32,7 @@
#include <limits.h>
#include "avcodec.h"
#include "get_bits.h"
+#include "libavutil/crc.h"
#define FORMAT_SIMPLE 1
#define FORMAT_ENCRYPTED 2
@@ -58,6 +59,7 @@ typedef struct TTAContext {
AVCodecContext *avctx;
AVFrame frame;
GetBitContext gb;
+ const AVCRC *crc_table;
int format, channels, bps, data_length;
int frame_length, last_frame_length, total_frames;
@@ -198,6 +200,20 @@ static const int64_t tta_channel_layouts[7] = {
AV_CH_LAYOUT_7POINT1_WIDE
};
+static int tta_check_crc(TTAContext *s, const uint8_t *buf, int buf_size)
+{
+ uint32_t crc, CRC;
+
+ CRC = AV_RL32(buf + buf_size);
+ crc = av_crc(s->crc_table, 0xFFFFFFFFU, buf, buf_size);
+ if (CRC != (crc ^ 0xFFFFFFFFU)) {
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ return 0;
+}
+
static av_cold int tta_decode_init(AVCodecContext * avctx)
{
TTAContext *s = avctx->priv_data;
@@ -211,6 +227,12 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
if (show_bits_long(&s->gb, 32) == AV_RL32("TTA1"))
{
+ if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ s->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE);
+ if (tta_check_crc(s, avctx->extradata, 18))
+ return AVERROR_INVALIDDATA;
+ }
+
/* signature */
skip_bits_long(&s->gb, 32);
@@ -274,6 +296,12 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
s->data_length, s->frame_length, s->last_frame_length, s->total_frames);
// FIXME: seek table
+ if (get_bits_left(&s->gb) < 32 * s->total_frames + 32)
+ av_log(avctx, AV_LOG_WARNING, "Seek table missing or too small\n");
+ else if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ if (tta_check_crc(s, avctx->extradata + 22, s->total_frames * 4))
+ return AVERROR_INVALIDDATA;
+ }
skip_bits_long(&s->gb, 32 * s->total_frames);
skip_bits_long(&s->gb, 32); // CRC32 of seektable
@@ -314,6 +342,11 @@ static int tta_decode_frame(AVCodecContext *avctx, void *data,
int cur_chan = 0, framelen = s->frame_length;
int32_t *p;
+ if (avctx->err_recognition & AV_EF_CRCCHECK) {
+ if (buf_size < 4 || tta_check_crc(s, buf, buf_size - 4))
+ return AVERROR_INVALIDDATA;
+ }
+
init_get_bits(&s->gb, buf, buf_size*8);
// FIXME: seeking