From 5de9ad899c83b4fa5225f44766fc8fcc760a68c9 Mon Sep 17 00:00:00 2001 From: Robert Obryk Date: Wed, 25 Jan 2017 17:10:32 +0100 Subject: [PATCH] Fix invalid memory access on small images. Calling butteraugli::Mask was sufficient to cause problems for small images. --- guetzli/processor.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/guetzli/processor.cc b/guetzli/processor.cc index 710ed8bb..6e093bcb 100644 --- a/guetzli/processor.cc +++ b/guetzli/processor.cc @@ -854,9 +854,13 @@ bool Process(const Params& params, ProcessStats* stats, if (stats == nullptr) { stats = &dummy_stats; } - ButteraugliComparator comparator(jpg.width, jpg.height, rgb, - params.butteraugli_target, stats); - bool ok = ProcessJpegData(params, jpg, &comparator, &out, stats); + std::unique_ptr comparator; + if (jpg.width >= 32 && jpg.height >= 32) { + comparator.reset( + new ButteraugliComparator(jpg.width, jpg.height, rgb, + params.butteraugli_target, stats)); + } + bool ok = ProcessJpegData(params, jpg, comparator.get(), &out, stats); *jpg_out = out.jpeg_data; return ok; } @@ -874,9 +878,13 @@ bool Process(const Params& params, ProcessStats* stats, if (stats == nullptr) { stats = &dummy_stats; } - ButteraugliComparator comparator(jpg.width, jpg.height, rgb, - params.butteraugli_target, stats); - bool ok = ProcessJpegData(params, jpg, &comparator, &out, stats); + std::unique_ptr comparator; + if (jpg.width >= 32 && jpg.height >= 32) { + comparator.reset( + new ButteraugliComparator(jpg.width, jpg.height, rgb, + params.butteraugli_target, stats)); + } + bool ok = ProcessJpegData(params, jpg, comparator.get(), &out, stats); *jpg_out = out.jpeg_data; return ok; }