Skip to content

Commit 831a9bb

Browse files
committed
Fix crash when opening image in editor
Do not access uninitialized raw image data. The raw data is requested when the demosaic mode is set to None and the cursor is moved over the image in the editor. It can occur before the raw data is loaded.
1 parent 0e835e8 commit 831a9bb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

rtengine/rawimagesource.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* You should have received a copy of the GNU General Public License
1717
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19+
#include <cassert>
1920
#include <cmath>
2021
#include <cstdlib>
2122
#include <iostream>
@@ -743,6 +744,8 @@ void RawImageSource::getWBMults(const ColorTemp &ctemp, const RAWParams &raw, st
743744

744745
void RawImageSource::getImage(const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const ToneCurveParams &hrp, const RAWParams &raw)
745746
{
747+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
748+
746749
MyMutex::MyLock lock(getImageMutex);
747750

748751
tran = defTransform(ri, tran);
@@ -1744,6 +1747,8 @@ void RawImageSource::preprocess(const RAWParams &raw, const LensProfParams &lens
17441747

17451748
void RawImageSource::demosaic(const RAWParams &raw, bool autoContrast, double &contrastThreshold, bool cache)
17461749
{
1750+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
1751+
17471752
MyTime t1, t2;
17481753
t1.set();
17491754

@@ -3837,6 +3842,8 @@ void RawImageSource::hlRecovery(const std::string &method, float* red, float* gr
38373842

38383843
void RawImageSource::getAutoExpHistogram(LUTu & histogram, int& histcompr)
38393844
{
3845+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
3846+
38403847
// BENCHFUN
38413848
histcompr = 3;
38423849

@@ -7481,6 +7488,8 @@ void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int
74817488

74827489
void RawImageSource::getAutoWBMultipliersitc(bool extra, double & tempref, double & greenref, double & tempitc, double & greenitc, float &temp0, float &delta, int &bia, int &dread, int &kcam, int &nocam, float &studgood, float &minchrom, int &kmin, float &minhist, float &maxhist, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double & rm, double & gm, double & bm, const WBParams & wbpar, const ColorManagementParams & cmp, const RAWParams & raw, const ToneCurveParams &hrp)
74837490
{
7491+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
7492+
74847493
// BENCHFUN
74857494
constexpr double clipHigh = 64000.0;
74867495

@@ -7710,6 +7719,8 @@ void RawImageSource::getAutoWBMultipliersitc(bool extra, double & tempref, doubl
77107719

77117720
void RawImageSource::getAutoWBMultipliers(double &rm, double &gm, double &bm)
77127721
{
7722+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
7723+
77137724
// BENCHFUN
77147725
constexpr double clipHigh = 64000.0;
77157726

@@ -7926,6 +7937,7 @@ void RawImageSource::getAutoWBMultipliers(double &rm, double &gm, double &bm)
79267937

79277938
ColorTemp RawImageSource::getSpotWB(std::vector<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &blue, int tran, double equal, StandardObserver observer)
79287939
{
7940+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
79297941

79307942
int x;
79317943
int y;
@@ -8265,7 +8277,7 @@ void RawImageSource::init()
82658277

82668278
void RawImageSource::getRawValues(int x, int y, int rotate, int &R, int &G, int &B)
82678279
{
8268-
if (d1x) { // Nikon D1x has special sensor. We just skip it
8280+
if (rawData.getWidth() != W || rawData.getHeight() != H || d1x) { // Nikon D1x has special sensor. We just skip it
82698281
R = G = B = 0;
82708282
return;
82718283
}
@@ -8313,6 +8325,8 @@ bool RawImageSource::isGainMapSupported() const
83138325

83148326
void RawImageSource::applyDngGainMap(const float black[4], const std::vector<GainMap> &gainMaps)
83158327
{
8328+
assert(rawData.getHeight() == H && rawData.getWidth() == W);
8329+
83168330
// now we can apply each gain map to raw_data
83178331
array2D<float> mvals[2][2];
83188332

0 commit comments

Comments
 (0)