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.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -24,6 +24,7 @@ · 23 unmodified lines | |||
| 24 | 24 | ||
| 25 | #include "libavutil/avassert.h" | 25 | #include "libavutil/avassert.h" |
| 26 | #include "libavutil/channel_layout.h" | 26 | #include "libavutil/channel_layout.h" |
| 27 | #include "libavutil/crc.h" | ||
| 27 | #include "libavutil/opt.h" | 28 | #include "libavutil/opt.h" |
| 28 | #include "lossless_audiodsp.h" | 29 | #include "lossless_audiodsp.h" |
| 29 | #include "avcodec.h" | 30 | #include "avcodec.h" |
| @@ -147,7 +148,8 @@ typedef struct APEContext { · 117 unmodified lines | |||
| 147 | int fset; ///< which filter set to use (calculated from compression level) | 148 | int fset; ///< which filter set to use (calculated from compression level) |
| 148 | int flags; ///< global decoder flags | 149 | int flags; ///< global decoder flags |
| 149 | 150 | ||
| 150 | uint32_t CRC; ///< frame CRC | 151 | uint32_t CRC; ///< signalled frame CRC |
| 152 | uint32_t CRC_state; ///< accumulated CRC | ||
| 151 | int frameflags; ///< frame flags | 153 | int frameflags; ///< frame flags |
| 152 | APEPredictor predictor; ///< predictor used for final reconstruction | 154 | APEPredictor predictor; ///< predictor used for final reconstruction |
| 153 | 155 | ||
| @@ -750,6 +752,7 @@ static int init_entropy_decoder(APEContext *ctx) · 596 unmodified lines | |||
| 750 | 752 | ||
| 751 | /* Read the frame flags if they exist */ | 753 | /* Read the frame flags if they exist */ |
| 752 | ctx->frameflags = 0; | 754 | ctx->frameflags = 0; |
| 755 | ctx->CRC_state = UINT32_MAX; | ||
| 753 | if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) { | 756 | if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) { |
| 754 | ctx->CRC &= ~0x80000000; | 757 | ctx->CRC &= ~0x80000000; |
| 755 | 758 | ||
| @@ -1577,6 +1580,27 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data, · 821 unmodified lines | |||
| 1577 | 1580 | ||
| 1578 | s->samples -= blockstodecode; | 1581 | s->samples -= blockstodecode; |
| 1579 | 1582 | ||
| 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 | |||
| 1580 | *got_frame_ptr = 1; | 1604 | *got_frame_ptr = 1; |
| 1581 | 1605 | ||
| 1582 | return !s->samples ? avpkt->size : 0; | 1606 | return !s->samples ? avpkt->size : 0; |