Fix: Crash when sampling Float2 images

Blender crashes when using math interpolation functions to sample Float2
images. That's because 3 components is intentionally left out of various
switch case. To fix this, we handle 3 components and assert for expected
components count.

Pull Request: https://projects.blender.org/blender/blender/pulls/137094
This commit is contained in:
Omar Emara
2025-04-07 15:25:15 +02:00
committed by Omar Emara
parent 84fb437355
commit 47471ca2b0

View File

@@ -160,6 +160,7 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer,
InterpWrapMode wrap_v)
{
BLI_assert(src_buffer && output);
BLI_assert(components > 0 && components <= 4);
#if BLI_HAVE_SSE4
if constexpr (std::is_same_v<T, uchar>) {
@@ -213,6 +214,10 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer,
if (components == 1) {
out[0] += data[0] * w;
}
else if (components == 2) {
out[0] += data[0] * w;
out[1] += data[1] * w;
}
else if (components == 3) {
out[0] += data[0] * w;
out[1] += data[1] * w;
@@ -242,6 +247,9 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer,
if (components == 1) {
output[0] = out[0];
}
else if (components == 2) {
copy_v2_v2(output, out);
}
else if (components == 3) {
copy_v3_v3(output, out);
}
@@ -253,6 +261,10 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer,
if (components == 1) {
output[0] = uchar(out[0] + 0.5f);
}
else if (components == 2) {
output[0] = uchar(out[0] + 0.5f);
output[1] = uchar(out[1] + 0.5f);
}
else if (components == 3) {
output[0] = uchar(out[0] + 0.5f);
output[1] = uchar(out[1] + 0.5f);
@@ -278,6 +290,8 @@ BLI_INLINE void bilinear_fl_impl(const float *buffer,
InterpWrapMode wrap_y)
{
BLI_assert(buffer && output);
BLI_assert(components > 0 && components <= 4);
float a, b;
float a_b, ma_b, a_mb, ma_mb;
int y1, y2, x1, x2;
@@ -363,6 +377,10 @@ BLI_INLINE void bilinear_fl_impl(const float *buffer,
if (components == 1) {
output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
}
else if (components == 2) {
output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
}
else if (components == 3) {
output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];