mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
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> (cherry picked from commit f64c0dffa13e6263de3fdff0058ab2fdb03ac1d6) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
63de02051d
commit
f5c6d42124
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user