Skip to content

Commit

Permalink
Properly unpoison/poison memory in SIMDfied noise decoding. (#319)
Browse files Browse the repository at this point in the history
This silences msan.
  • Loading branch information
veluca93 committed Jul 15, 2021
1 parent b1f8016 commit 98231ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/jxl/dec_noise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lib/jxl/chroma_from_luma.h"
#include "lib/jxl/image_ops.h"
#include "lib/jxl/opsin_params.h"
#include "lib/jxl/sanitizers.h"
#include "lib/jxl/xorshift128plus-inl.h"
HWY_BEFORE_NAMESPACE();
namespace jxl {
Expand Down Expand Up @@ -215,13 +216,19 @@ void AddNoise(const NoiseParams& noise_params, const Rect& noise_rect,
float ytox = cmap.YtoXRatio(0);
float ytob = cmap.YtoBRatio(0);

const size_t xsize_v = RoundUpTo(xsize, Lanes(d));

for (size_t y = 0; y < ysize; ++y) {
float* JXL_RESTRICT row_x = opsin_rect.PlaneRow(opsin, 0, y);
float* JXL_RESTRICT row_y = opsin_rect.PlaneRow(opsin, 1, y);
float* JXL_RESTRICT row_b = opsin_rect.PlaneRow(opsin, 2, y);
const float* JXL_RESTRICT row_rnd_r = noise_rect.ConstPlaneRow(noise, 0, y);
const float* JXL_RESTRICT row_rnd_g = noise_rect.ConstPlaneRow(noise, 1, y);
const float* JXL_RESTRICT row_rnd_c = noise_rect.ConstPlaneRow(noise, 2, y);
// Needed by the calls to Floor() in StrengthEvalLut. Only arithmetic and
// shuffles are otherwise done on the data, so this is safe.
msan::UnpoisonMemory(row_x + xsize, (xsize_v - xsize) * sizeof(float));
msan::UnpoisonMemory(row_y + xsize, (xsize_v - xsize) * sizeof(float));
for (size_t x = 0; x < xsize; x += Lanes(d)) {
const auto vx = Load(d, row_x + x);
const auto vy = Load(d, row_y + x);
Expand All @@ -238,6 +245,9 @@ void AddNoise(const NoiseParams& noise_params, const Rect& noise_rect,
noise_strength_r, ytox, ytob, row_x + x, row_y + x,
row_b + x);
}
msan::PoisonMemory(row_x + xsize, (xsize_v - xsize) * sizeof(float));
msan::PoisonMemory(row_y + xsize, (xsize_v - xsize) * sizeof(float));
msan::PoisonMemory(row_b + xsize, (xsize_v - xsize) * sizeof(float));
}
}

Expand Down

0 comments on commit 98231ab

Please sign in to comment.