diff options
author | Kinan Hakim <kinan@google.com> | 2016-01-25 19:22:32 +0100 |
---|---|---|
committer | Kinan Hakim <kinan@google.com> | 2016-01-25 19:41:51 +0100 |
commit | ae846f59545feffb3642d12f47901cc1f46a2788 (patch) | |
tree | 642f41815efc741272551b3feea06706b80a2b6f | |
parent | 2bef8b90e267af3a2b74301eb415d0a5d04657fa (diff) | |
download | dng_sdk-ae846f59545feffb3642d12f47901cc1f46a2788.tar.gz |
Fix Division by Zero
Change-Id: I9832ab5949ac9e0d0051645869d4cda7ce8860c8
-rw-r--r-- | source/dng_color_spec.cpp | 12 | ||||
-rw-r--r-- | source/dng_render.cpp | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/source/dng_color_spec.cpp b/source/dng_color_spec.cpp index 139cdee..807ee4d 100644 --- a/source/dng_color_spec.cpp +++ b/source/dng_color_spec.cpp @@ -409,8 +409,12 @@ void dng_color_spec::SetWhiteXY (const dng_xy_coord &white) // Find the camera white values.
fCameraWhite = colorMatrix * XYtoXYZ (fWhiteXY);
-
- real64 whiteScale = 1.0 / MaxEntry (fCameraWhite);
+ real64 cameraWhiteMaxEntry = MaxEntry (fCameraWhite);
+ if (cameraWhiteMaxEntry == 0)
+ {
+ ThrowBadFormat ();
+ }
+ real64 whiteScale = 1.0 / cameraWhiteMaxEntry;
for (uint32 j = 0; j < fChannels; j++)
{
@@ -430,6 +434,10 @@ void dng_color_spec::SetWhiteXY (const dng_xy_coord &white) real64 scale = MaxEntry (fPCStoCamera * PCStoXYZ ());
+ if (scale == 0)
+ {
+ ThrowBadFormat ();
+ }
fPCStoCamera = (1.0 / scale) * fPCStoCamera;
// If we have a forward matrix, then just use that.
diff --git a/source/dng_render.cpp b/source/dng_render.cpp index bd8d0f8..e3d9940 100644 --- a/source/dng_render.cpp +++ b/source/dng_render.cpp @@ -34,13 +34,17 @@ dng_function_exposure_ramp::dng_function_exposure_ramp (real64 white, real64 black, real64 minBlack) - : fSlope ((white == black) ? 1.0f : 1.0 / (white - black)) + : fSlope ((white == black) ? 0.0f : 1.0 / (white - black)) , fBlack (black) , fRadius (0.0) , fQScale (0.0) { + if (fSlope == 0.0) + { + ThrowBadFormat (); + } const real64 kMaxCurveX = 0.5; // Fraction of minBlack. |