diff --git a/libavcodec/iff.c b/libavcodec/iff.c index 4bde0a8117..f08a0f70ce 100644 --- a/libavcodec/iff.c +++ b/libavcodec/iff.c @@ -488,12 +488,12 @@ static int decode_byterun(uint8_t *dst, int dst_size, unsigned length; const int8_t value = *buf++; if (value >= 0) { - length = value + 1; - memcpy(dst + x, buf, FFMIN3(length, dst_size - x, buf_end - buf)); + length = FFMIN3(value + 1, dst_size - x, buf_end - buf); + memcpy(dst + x, buf, length); buf += length; } else if (value > -128) { - length = -value + 1; - memset(dst + x, *buf++, FFMIN(length, dst_size - x)); + length = FFMIN(-value + 1, dst_size - x); + memset(dst + x, *buf++, length); } else { // noop continue; }