History

apedec: add ability to check CRC

The CRC flag is only signalled once every few minutes but CRC is still always present so the patch uses the file version instead. CRC on 24-bit files wants non-padded samples so skip such files. Some corrupt samples may have been output before the final check depending on the -max_samples setting.

Lynne committed 7 years ago

Commit 1cc8eec1 parent 731c7751 file · +25 −1Browse files

Showing the changes to libavcodec/apedec.c (1 of 1 file). Show all

Unified · Split

libavcodec/apedec.c+25−1
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424
2525 #include "libavutil/avassert.h"
2626 #include "libavutil/channel_layout.h"
27+#include "libavutil/crc.h"
2728 #include "libavutil/opt.h"
2829 #include "lossless_audiodsp.h"
2930 #include "avcodec.h"
@@ -147,7 +148,8 @@ typedef struct APEContext { · 117 unmodified lines
147148 int fset; ///< which filter set to use (calculated from compression level)
148149 int flags; ///< global decoder flags
149150
150− uint32_t CRC; ///< frame CRC
151+ uint32_t CRC; ///< signalled frame CRC
152+ uint32_t CRC_state; ///< accumulated CRC
151153 int frameflags; ///< frame flags
152154 APEPredictor predictor; ///< predictor used for final reconstruction
153155
@@ -750,6 +752,7 @@ static int init_entropy_decoder(APEContext *ctx) · 596 unmodified lines
750752
751753 /* Read the frame flags if they exist */
752754 ctx->frameflags = 0;
755+ ctx->CRC_state = UINT32_MAX;
753756 if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) {
754757 ctx->CRC &= ~0x80000000;
755758
@@ -1577,6 +1580,27 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, · 821 unmodified lines
15771580
15781581 s->samples -= blockstodecode;
15791582
1583+ if (avctx->err_recognition & AV_EF_CRCCHECK &&
1584+ s->fileversion >= 3900 && s->bps < 24) {
1585+ uint32_t crc = s->CRC_state;
1586+ const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
1587+ for (i = 0; i < blockstodecode; i++) {
1588+ for (ch = 0; ch < s->channels; ch++) {
1589+ uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3));
1590+ crc = av_crc(crc_tab, crc, smp, s->bps >> 3);
1591+ }
1592+ }
1593+
1594+ if (!s->samples && (~crc >> 1) ^ s->CRC) {
1595+ av_log(avctx, AV_LOG_ERROR, "CRC mismatch! Previously decoded "
1596+ "frames may have been affected as well.\n");
1597+ if (avctx->err_recognition & AV_EF_EXPLODE)
1598+ return AVERROR_INVALIDDATA;
1599+ }
1600+
1601+ s->CRC_state = crc;
1602+ }
1603+
15801604 *got_frame_ptr = 1;
15811605
15821606 return !s->samples ? avpkt->size : 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t