Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Unified Diff: src/images/SkImageDecoder_libpng.cpp

Issue 24449003: Make Jpeg decoding more fault resistant. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: lint changes, bugfix, description changed Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/images/SkImageDecoder_libpng.cpp
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index e942f21c787c5e01f6d11ea392309ca6aad562b7..1d37a8c73419d91e67087fea8a551176b911f604 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -199,6 +199,9 @@ static bool hasTransparencyInPalette(png_structp png_ptr, png_infop info_ptr) {
return false;
}
+void do_nothing(png_structp, png_const_charp) { /* do nothing */ }
scroggo 2013/10/01 22:04:14 More specific name?
+
+
bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
png_infop *info_ptrp) {
/* Create and initialize the png_struct with the desired error handler
@@ -212,6 +215,12 @@ bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
if (png_ptr == NULL) {
return false;
}
+
+ png_error_ptr warning_fn = &do_nothing;
scroggo 2013/10/01 22:04:14 Again, this stuff should only be done #if !define
+ png_voidp error_ptr = png_get_error_ptr(png_ptr);
+ png_error_ptr error_fn = NULL; // leave as default
+ png_set_error_fn(png_ptr, error_ptr, error_fn, warning_fn);
+
*png_ptrp = png_ptr;
/* Allocate/initialize the memory for image information. */
@@ -495,9 +504,13 @@ bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
transpColor->green >> 8,
transpColor->blue >> 8);
} else {
- *theTranspColorp = SkPackARGB32(0xFF, transpColor->red,
- transpColor->green,
- transpColor->blue);
+ *theTranspColorp = SkPackARGB32(0xFF,
+ 0xFF & (transpColor->red),
+ 0xFF & (transpColor->green),
+ 0xFF & (transpColor->blue));
+ /* We apply the mask because in a very small
scroggo 2013/10/01 22:04:14 Shouldn't this go above the code it applies to?
+ number of corrupt PNGs, (transpColor->red > 255)
+ and (bitDepth == 8), for certain versions of libpng. */
}
} else { // gray
if (16 == bitDepth) {
@@ -505,9 +518,10 @@ bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
transpColor->gray >> 8,
transpColor->gray >> 8);
} else {
- *theTranspColorp = SkPackARGB32(0xFF, transpColor->gray,
- transpColor->gray,
- transpColor->gray);
+ *theTranspColorp = SkPackARGB32(0xFF,
scroggo 2013/10/01 22:04:14 Similar comment explaining the mask?
+ 0xFF & (transpColor->gray),
+ 0xFF & (transpColor->gray),
+ 0xFF & (transpColor->gray));
}
}
}

Powered by Google App Engine
This is Rietveld 408576698