X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Ftiff.c;h=7ccda51404ad021deaca101a6c05323b8327d67e;hb=94eb600f354c486fd3a9b50e052e809452673fcf;hp=4721e9444912a0a1e3e25e4330d7972a5a130cd9;hpb=1f8e1c209db2ec098edd7880a4ac88864615d674;p=ffmpeg diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 4721e944491..7ccda51404a 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -772,9 +772,18 @@ static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den) int offset = tag == TIFF_YRES ? 2 : 0; s->res[offset++] = num; s->res[offset] = den; - if (s->res[0] && s->res[1] && s->res[2] && s->res[3]) + if (s->res[0] && s->res[1] && s->res[2] && s->res[3]) { + uint64_t num = s->res[2] * (uint64_t)s->res[1]; + uint64_t den = s->res[0] * (uint64_t)s->res[3]; + if (num > INT64_MAX || den > INT64_MAX) { + num = num >> 1; + den = den >> 1; + } av_reduce(&s->avctx->sample_aspect_ratio.num, &s->avctx->sample_aspect_ratio.den, - s->res[2] * (uint64_t)s->res[1], s->res[0] * (uint64_t)s->res[3], INT32_MAX); + num, den, INT32_MAX); + if (!s->avctx->sample_aspect_ratio.den) + s->avctx->sample_aspect_ratio = (AVRational) {0, 1}; + } } static int tiff_decode_tag(TiffContext *s, AVFrame *frame)