From 633cbfdd7803b65e4e80a64047070001f9abe4ba Mon Sep 17 00:00:00 2001 From: Yannis Guyon Date: Mon, 11 Dec 2023 10:43:32 +0100 Subject: [PATCH] Fix avifImageYUVToRGB() job count (#1865) Found by avif_fuzztest_yuvrgb --- src/reformat.c | 5 +++-- tests/gtest/avif_fuzztest_yuvrgb.cc | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/reformat.c b/src/reformat.c index e9e60275e3..a8e2a553e9 100644 --- a/src/reformat.c +++ b/src/reformat.c @@ -4,7 +4,7 @@ #include "avif/internal.h" #include -#include +#include #include #if defined(_WIN32) @@ -1597,6 +1597,7 @@ avifResult avifImageYUVToRGB(const avifImage * image, avifRGBImage * rgb) int rowsPerJob = image->height / jobs; if (rowsPerJob % 2) { ++rowsPerJob; + jobs = (image->height + rowsPerJob - 1) / rowsPerJob; // ceil } const int rowsForLastJob = image->height - rowsPerJob * (jobs - 1); int startRow = 0; @@ -1624,7 +1625,7 @@ avifResult avifImageYUVToRGB(const avifImage * image, avifRGBImage * rgb) } } } - // If above loop ran successfully, Run the first job in the current thread. + // If above loop ran successfully, run the first job in the current thread. if (i == jobs) { avifImageYUVToRGBThreadWorker(&threadData[0]); } diff --git a/tests/gtest/avif_fuzztest_yuvrgb.cc b/tests/gtest/avif_fuzztest_yuvrgb.cc index 75338e5c6f..6a28f417cd 100644 --- a/tests/gtest/avif_fuzztest_yuvrgb.cc +++ b/tests/gtest/avif_fuzztest_yuvrgb.cc @@ -1,6 +1,8 @@ // Copyright 2023 Google LLC // SPDX-License-Identifier: BSD-2-Clause +#include + #include "avif/avif.h" #include "avif_fuzztest_helpers.h" #include "aviftest_helpers.h" @@ -48,7 +50,7 @@ void Convert(ImagePtr image, int rgb_depth, int rgb_format, // Fill pixels with something, so that avifImageRGBToYUV() can be called. AvifRgbImage rgb_ok(image.get(), rgb_depth, AVIF_RGB_FORMAT_RGBA); ASSERT_EQ(avifImageYUVToRGB(image.get(), &rgb_ok), AVIF_RESULT_OK); - memcpy(rgb.pixels, rgb_ok.pixels, rgb.rowBytes * rgb.height); + std::memcpy(rgb.pixels, rgb_ok.pixels, rgb.rowBytes * rgb.height); } ASSERT_EQ(avifImageRGBToYUV(image.get(), &rgb), expected_rgb_to_yuv_result);