[FFmpeg-devel] [PATCH 3/3] avcodec/utils: Optimize ff_color_frame()

Michael Niedermayer michael at niedermayer.cc
Mon Dec 24 02:14:51 EET 2018


Fixes: Timeout
Fixes: 10709/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-5630617975259136

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/utils.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index d519b16092..5f8bec6df4 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -423,8 +423,13 @@ void ff_color_frame(AVFrame *frame, const int c[4])
         int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
         for (y = 0; y < height; y++) {
             if (desc->comp[0].depth >= 9) {
-                for (x = 0; x<bytes; x++)
-                    ((uint16_t*)dst)[x] = c[p];
+                uint64_t v = c[p] * 0x0001000100010001ULL;
+                for (x = 0; x<2*bytes-15; x+=16) {
+                    AV_WN64(dst+x  , v);
+                    AV_WN64(dst+x+8, v);
+                }
+                for (; x<bytes; x++)
+                    ((uint16_t*)dst)[x] = v;
             }else
                 memset(dst, c[p], bytes);
             dst += frame->linesize[p];
-- 
2.20.1



More information about the ffmpeg-devel mailing list