aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2018-12-25 23:15:20 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2019-01-20 21:42:20 +0100
commitf64c0dffa13e6263de3fdff0058ab2fdb03ac1d6 (patch)
treeb8c12258322fdb6829b3528a09431f67e498be78 /libavutil
parent12b1338be376a3e5fb606d9fe41b58dc4a9e62c7 (diff)
downloadffmpeg-f64c0dffa13e6263de3fdff0058ab2fdb03ac1d6.tar.gz
avutil/imgutils: Optimize memset_bytes() by using av_memcpy_backptr()
This is strongly based on code by Marton Balint, and depends on the previous commit Fixes: Timeout Fixes: 11502/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 Before: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 in 11209 ms After: Executed clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WCMV_fuzzer-5664893810769920 in 4104 ms Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/imgutils.c27
1 files changed, 5 insertions, 22 deletions
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 4938a7ef67..afc73e2def 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -501,7 +501,6 @@ int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear,
size_t clear_size)
{
- size_t pos = 0;
int same = 1;
int i;
@@ -521,28 +520,12 @@ static void memset_bytes(uint8_t *dst, size_t dst_size, uint8_t *clear,
if (clear_size == 1) {
memset(dst, clear[0], dst_size);
dst_size = 0;
- } else if (clear_size == 2) {
- uint16_t val = AV_RN16(clear);
- for (; dst_size >= 2; dst_size -= 2) {
- AV_WN16(dst, val);
- dst += 2;
- }
- } else if (clear_size == 4) {
- uint32_t val = AV_RN32(clear);
- for (; dst_size >= 4; dst_size -= 4) {
- AV_WN32(dst, val);
- dst += 4;
- }
- } else if (clear_size == 8) {
- uint32_t val = AV_RN64(clear);
- for (; dst_size >= 8; dst_size -= 8) {
- AV_WN64(dst, val);
- dst += 8;
- }
+ } else {
+ if (clear_size > dst_size)
+ clear_size = dst_size;
+ memcpy(dst, clear, clear_size);
+ av_memcpy_backptr(dst + clear_size, clear_size, dst_size - clear_size);
}
-
- for (; dst_size; dst_size--)
- *dst++ = clear[pos++ % clear_size];
}
// Maximum size in bytes of a plane element (usually a pixel, or multiple pixels