summaryrefslogtreecommitdiff
path: root/pngset.c
diff options
context:
space:
mode:
authorJohn Bowler <jbowler@acm.org>2011-06-11 06:42:06 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2011-06-11 06:42:06 -0500
commitd2f0bc2d13e6923c043d76c1d99ad2c532d78ada (patch)
tree30b8551b5085142c6818edc3bc67a7031f0d8e67 /pngset.c
parentb011fe1c12183271752245baa5988c26b1f90a20 (diff)
downloadlibpng-d2f0bc2d13e6923c043d76c1d99ad2c532d78ada.tar.gz
[devel] Improved gamma range checks and other things OpenWatcom warns about.
Diffstat (limited to 'pngset.c')
-rw-r--r--pngset.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/pngset.c b/pngset.c
index 2c58f7fc7..5fe984120 100644
--- a/pngset.c
+++ b/pngset.c
@@ -94,15 +94,16 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
if (png_ptr == NULL || info_ptr == NULL)
return;
- /* Previously these values were limited, however they must be
- * wrong, therefore storing them (and setting PNG_INFO_gAMA)
- * must be wrong too.
+ /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
+ * occur. Since the fixed point representation is assymetrical it is
+ * possible for 1/gamma to overflow the limit of 21474 and this means the
+ * gamma value must be at least 5/100000 and hence at most 20000.0. For
+ * safety the limits here are a little narrower. The values are 0.00016 to
+ * 6250.0, which are truely ridiculous gammma values (and will produce
+ * displays that are all black or all white.)
*/
- if (file_gamma > (png_fixed_point)PNG_UINT_31_MAX)
- png_warning(png_ptr, "Gamma too large, ignored");
-
- else if (file_gamma <= 0)
- png_warning(png_ptr, "Negative or zero gamma ignored");
+ if (file_gamma < 16 || file_gamma > 625000000)
+ png_warning(png_ptr, "Out of range gamma value ignored");
else
{
@@ -340,11 +341,11 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
if (unit != 1 && unit != 2)
png_error(png_ptr, "Invalid sCAL unit");
- if (swidth == NULL || (lengthw = png_strlen(swidth)) <= 0 ||
+ if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 ||
swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))
png_error(png_ptr, "Invalid sCAL width");
- if (sheight == NULL || (lengthh = png_strlen(sheight)) <= 0 ||
+ if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 ||
sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))
png_error(png_ptr, "Invalid sCAL height");