diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 927763e24d..f303ed769f 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -130,7 +130,7 @@ int ff_slice_coord(const FFV1Context *f, int width, int sx, int num_h_slices, in int mpw = 1<version < 4 || f->version == 4 && f->micro_version < 3) + if (f->combined_version <= 0x40002) return width * sx / num_h_slices; sx = (2LL * awidth * sx + num_h_slices * mpw) / (2 * num_h_slices * mpw) * mpw; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 6b4ffca3f9..419c53093f 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -113,6 +113,7 @@ typedef struct FFV1Context { uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; int version; int micro_version; + int combined_version; int width, height; int chroma_planes; int chroma_h_shift, chroma_v_shift; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 46aaaadb9c..fcf3d525ac 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -307,7 +307,7 @@ static int decode_slice(AVCodecContext *c, void *arg) y = sc->slice_y; if (ac == AC_GOLOMB_RICE) { - if (f->version == 3 && f->micro_version > 1 || f->version > 3) + if (f->combined_version >= 0x30002) get_rac(&sc->c, (uint8_t[]) { 129 }); sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0; init_get_bits(&gb, @@ -433,11 +433,13 @@ static int read_extra_header(FFV1Context *f) f->version); return AVERROR_PATCHWELCOME; } + f->combined_version = f->version << 16; if (f->version > 2) { c.bytestream_end -= 4; f->micro_version = get_symbol(&c, state, 0); - if (f->micro_version < 0) + if (f->micro_version < 0 || f->micro_version > 65535) return AVERROR_INVALIDDATA; + f->combined_version += f->micro_version; } f->ac = get_symbol(&c, state, 0); @@ -505,7 +507,7 @@ static int read_extra_header(FFV1Context *f) f->ec = get_symbol(&c, state, 0); if (f->ec >= 2) f->crcref = 0x7a8c4079; - if (f->micro_version > 2) + if (f->combined_version >= 0x30003) f->intra = get_symbol(&c, state, 0); } @@ -1104,6 +1106,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) fdst->version = fsrc->version; fdst->micro_version = fsrc->micro_version; + fdst->combined_version = fsrc->combined_version; fdst->chroma_planes = fsrc->chroma_planes; fdst->chroma_h_shift = fsrc->chroma_h_shift; fdst->chroma_v_shift = fsrc->chroma_v_shift; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index e2db1b4164..c6f450ae6c 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -414,11 +414,13 @@ av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx) ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); put_symbol(&c, state, f->version, 0); + f->combined_version = f->version << 16; if (f->version > 2) { if (f->version == 3) { f->micro_version = 4; } else if (f->version == 4) f->micro_version = 3; + f->combined_version += f->micro_version; put_symbol(&c, state, f->micro_version, 0); }