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

Unified Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 24449003: Make Jpeg decoding more fault resistant. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: description change Created 7 years, 2 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_libjpeg.cpp
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 3b3ea887e3cde437d7469d2a43126a2cb604a6eb..28c3edeace5668a157b98d53d52294c3bd75282c 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -19,6 +19,10 @@
#include "SkRect.h"
#include "SkCanvas.h"
+#if defined(SK_DEBUG)
+#include "SkRTConf.h" // SK_CONF_DECLARE
+#endif // defined(SK_DEBUG)
+
#include <stdio.h>
extern "C" {
#include "jpeglib.h"
@@ -35,6 +39,12 @@ extern "C" {
// If ANDROID_RGB is defined by in the jpeg headers it indicates that jpeg offers
// support for two additional formats (1) JCS_RGBA_8888 and (2) JCS_RGB_565.
+#if defined(SK_DEBUG)
+SK_CONF_DECLARE(bool, c_suppressJPEGImageDecoderWarnings,
+ "images.jpeg.suppressDecoderWarnings", false,
+ "Suppress most JPG warnings when calling decode functions.");
+#endif // defined(SK_DEBUG)
+
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
@@ -54,12 +64,27 @@ static void overwrite_mem_buffer_size(jpeg_decompress_struct* cinfo) {
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
+static void do_nothing_emit_message(jpeg_common_struct*, int) {
+ /* do nothing */
+}
+
static void initialize_info(jpeg_decompress_struct* cinfo, skjpeg_source_mgr* src_mgr) {
SkASSERT(cinfo != NULL);
SkASSERT(src_mgr != NULL);
jpeg_create_decompress(cinfo);
overwrite_mem_buffer_size(cinfo);
cinfo->src = src_mgr;
+#if defined(SK_DEBUG)
+ /* To suppress warnings with a SK_DEBUG binary, set the
+ * environment variable "skia_images_jpeg_suppressDecoderWarnings"
+ * to "true". Inside a program that links to skia:
+ * SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); */
+ if (c_suppressJPEGImageDecoderWarnings) {
+ cinfo->err->emit_message = &do_nothing_emit_message;
+ }
+#else // Always suppress in release mode.
+ cinfo->err->emit_message = &do_nothing_emit_message;
+#endif //defined(SK_DEBUG)
}
#ifdef SK_BUILD_FOR_ANDROID
@@ -556,7 +581,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
// if row_count == 0, then we didn't get a scanline, so abort.
// if we supported partial images, we might return true in this case
if (0 == row_count) {
- return return_false(cinfo, *bm, "read_scanlines");
+ return true;
scroggo 2013/10/02 17:05:04 The remaining rows will still be uninitialized.
}
if (this->shouldCancelDecode()) {
return return_false(cinfo, *bm, "shouldCancelDecode");
@@ -606,7 +631,7 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
JSAMPLE* rowptr = (JSAMPLE*)srcRow;
int row_count = jpeg_read_scanlines(&cinfo, &rowptr, 1);
if (0 == row_count) {
- return return_false(cinfo, *bm, "read_scanlines");
+ return true;
scroggo 2013/10/02 17:05:04 Ditto
}
if (this->shouldCancelDecode()) {
return return_false(cinfo, *bm, "shouldCancelDecode");
@@ -788,7 +813,7 @@ bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) {
// if row_count == 0, then we didn't get a scanline, so abort.
// if we supported partial images, we might return true in this case
if (0 == rowCount) {
- return return_false(*cinfo, bitmap, "read_scanlines");
+ return true;
scroggo 2013/10/02 17:05:04 Ditto
}
if (this->shouldCancelDecode()) {
return return_false(*cinfo, bitmap, "shouldCancelDecode");
@@ -845,7 +870,7 @@ bool SkJPEGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) {
JSAMPLE* rowptr = (JSAMPLE*)srcRow;
int row_count = jpeg_read_tile_scanline(cinfo, fImageIndex->huffmanIndex(), &rowptr);
if (0 == row_count) {
- return return_false(*cinfo, bitmap, "read_scanlines");
+ return true;
scroggo 2013/10/02 17:05:04 Ditto
}
if (this->shouldCancelDecode()) {
return return_false(*cinfo, bitmap, "shouldCancelDecode");

Powered by Google App Engine
This is Rietveld 408576698