It more directly shows that ff_flac_decode_frame_header() does not modify the AVCodecContext given to it at all; and it would not be allowed to do so, given that it is used by the parser when it is still unknown whether said frame header is even valid.
Unified · Split
| @@ -48,14 +48,14 @@ static int64_t get_utf8(GetBitContext *gb) · 47 unmodified lines | |||
| 48 | return val; | 48 | return val; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, | 51 | int ff_flac_decode_frame_header(void *logctx, GetBitContext *gb, |
| 52 | FLACFrameInfo *fi, int log_level_offset) | 52 | FLACFrameInfo *fi, int log_level_offset) |
| 53 | { | 53 | { |
| 54 | int bs_code, sr_code, bps_code; | 54 | int bs_code, sr_code, bps_code; |
| 55 | 55 | ||
| 56 | /* frame sync code */ | 56 | /* frame sync code */ |
| 57 | if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) { | 57 | if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) { |
| 58 | av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n"); | 58 | av_log(logctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\n"); |
| 59 | return AVERROR_INVALIDDATA; | 59 | return AVERROR_INVALIDDATA; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -75,7 +75,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 13 unmodified lines | |||
| 75 | fi->channels = 2; | 75 | fi->channels = 2; |
| 76 | fi->ch_mode -= FLAC_MAX_CHANNELS - 1; | 76 | fi->ch_mode -= FLAC_MAX_CHANNELS - 1; |
| 77 | } else { | 77 | } else { |
| 78 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 78 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 79 | "invalid channel mode: %d\n", fi->ch_mode); | 79 | "invalid channel mode: %d\n", fi->ch_mode); |
| 80 | return AVERROR_INVALIDDATA; | 80 | return AVERROR_INVALIDDATA; |
| 81 | } | 81 | } |
| @@ -83,7 +83,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 1 unmodified line | |||
| 83 | /* bits per sample */ | 83 | /* bits per sample */ |
| 84 | bps_code = get_bits(gb, 3); | 84 | bps_code = get_bits(gb, 3); |
| 85 | if (bps_code == 3) { | 85 | if (bps_code == 3) { |
| 86 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 86 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 87 | "invalid sample size code (%d)\n", | 87 | "invalid sample size code (%d)\n", |
| 88 | bps_code); | 88 | bps_code); |
| 89 | return AVERROR_INVALIDDATA; | 89 | return AVERROR_INVALIDDATA; |
| @@ -92,7 +92,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 2 unmodified lines | |||
| 92 | 92 | ||
| 93 | /* reserved bit */ | 93 | /* reserved bit */ |
| 94 | if (get_bits1(gb)) { | 94 | if (get_bits1(gb)) { |
| 95 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 95 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 96 | "broken stream, invalid padding\n"); | 96 | "broken stream, invalid padding\n"); |
| 97 | return AVERROR_INVALIDDATA; | 97 | return AVERROR_INVALIDDATA; |
| 98 | } | 98 | } |
| @@ -100,14 +100,14 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 1 unmodified line | |||
| 100 | /* sample or frame count */ | 100 | /* sample or frame count */ |
| 101 | fi->frame_or_sample_num = get_utf8(gb); | 101 | fi->frame_or_sample_num = get_utf8(gb); |
| 102 | if (fi->frame_or_sample_num < 0) { | 102 | if (fi->frame_or_sample_num < 0) { |
| 103 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 103 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 104 | "sample/frame number invalid; utf8 fscked\n"); | 104 | "sample/frame number invalid; utf8 fscked\n"); |
| 105 | return AVERROR_INVALIDDATA; | 105 | return AVERROR_INVALIDDATA; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | /* blocksize */ | 108 | /* blocksize */ |
| 109 | if (bs_code == 0) { | 109 | if (bs_code == 0) { |
| 110 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 110 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 111 | "reserved blocksize code: 0\n"); | 111 | "reserved blocksize code: 0\n"); |
| 112 | return AVERROR_INVALIDDATA; | 112 | return AVERROR_INVALIDDATA; |
| 113 | } else if (bs_code == 6) { | 113 | } else if (bs_code == 6) { |
| @@ -128,7 +128,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 14 unmodified lines | |||
| 128 | } else if (sr_code == 14) { | 128 | } else if (sr_code == 14) { |
| 129 | fi->samplerate = get_bits(gb, 16) * 10; | 129 | fi->samplerate = get_bits(gb, 16) * 10; |
| 130 | } else { | 130 | } else { |
| 131 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 131 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 132 | "illegal sample rate code %d\n", | 132 | "illegal sample rate code %d\n", |
| 133 | sr_code); | 133 | sr_code); |
| 134 | return AVERROR_INVALIDDATA; | 134 | return AVERROR_INVALIDDATA; |
| @@ -138,7 +138,7 @@ int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 3 unmodified lines | |||
| 138 | skip_bits(gb, 8); | 138 | skip_bits(gb, 8); |
| 139 | if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer, | 139 | if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer, |
| 140 | get_bits_count(gb)/8)) { | 140 | get_bits_count(gb)/8)) { |
| 141 | av_log(avctx, AV_LOG_ERROR + log_level_offset, | 141 | av_log(logctx, AV_LOG_ERROR + log_level_offset, |
| 142 | "header crc mismatch\n"); | 142 | "header crc mismatch\n"); |
| 143 | return AVERROR_INVALIDDATA; | 143 | return AVERROR_INVALIDDATA; |
| 144 | } | 144 | } |
| @@ -75,13 +75,13 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx, · 74 unmodified lines | |||
| 75 | 75 | ||
| 76 | /** | 76 | /** |
| 77 | * Validate and decode a frame header. | 77 | * Validate and decode a frame header. |
| 78 | * @param avctx AVCodecContext to use as av_log() context | 78 | * @param logctx context for logging |
| 79 | * @param gb GetBitContext from which to read frame header | 79 | * @param gb GetBitContext from which to read frame header |
| 80 | * @param[out] fi frame information | 80 | * @param[out] fi frame information |
| 81 | * @param log_level_offset log level offset. can be used to silence error messages. | 81 | * @param log_level_offset log level offset. can be used to silence error messages. |
| 82 | * @return non-zero on error, 0 if ok | 82 | * @return non-zero on error, 0 if ok |
| 83 | */ | 83 | */ |
| 84 | int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, | 84 | int ff_flac_decode_frame_header(void *logctx, GetBitContext *gb, |
| 85 | FLACFrameInfo *fi, int log_level_offset); | 85 | FLACFrameInfo *fi, int log_level_offset); |
| 86 | 86 | ||
| 87 | void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels); | 87 | void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels); |