Skip to content

Commit

Permalink
Fix avifImageYUVToRGB() job count (#1865)
Browse files Browse the repository at this point in the history
Found by avif_fuzztest_yuvrgb
  • Loading branch information
y-guyon authored Dec 11, 2023
1 parent 4803d5a commit 633cbfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/reformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "avif/internal.h"

#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <string.h>

#if defined(_WIN32)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/gtest/avif_fuzztest_yuvrgb.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2023 Google LLC
// SPDX-License-Identifier: BSD-2-Clause

#include <cstring>

#include "avif/avif.h"
#include "avif_fuzztest_helpers.h"
#include "aviftest_helpers.h"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 633cbfd

Please sign in to comment.