Index: src/images/SkImageDecoder_libjpeg.cpp |
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp |
index d32e2a21c91bea0fe06e472a5e6cce22518f41c5..caa1300124443a5f81aba764ea0d0d4e4d963fe0 100644 |
--- a/src/images/SkImageDecoder_libjpeg.cpp |
+++ b/src/images/SkImageDecoder_libjpeg.cpp |
@@ -768,14 +768,25 @@ static SkISize compute_yuv_size(const jpeg_decompress_struct& info, int componen |
info.cur_comp_info[component]->downsampled_height); |
} |
-static void update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize componentSizes[3], |
+static bool contains_three_planes(const jpeg_decompress_struct& cinfo) { |
hal.canary
2015/03/17 21:32:48
// Either explain why this is needed or note that
|
+ return cinfo.cur_comp_info[0] && cinfo.cur_comp_info[1] && cinfo.cur_comp_info[2]; |
+} |
+ |
+static bool update_components_sizes(const jpeg_decompress_struct& cinfo, SkISize componentSizes[3], |
SizeType sizeType) { |
+ if (!contains_three_planes(cinfo)) { |
+ return false; |
+ } |
for (int i = 0; i < 3; ++i) { |
componentSizes[i] = compute_yuv_size(cinfo, i, sizeType); |
} |
+ return true; |
} |
static bool output_raw_data(jpeg_decompress_struct& cinfo, void* planes[3], size_t rowBytes[3]) { |
+ if (!contains_three_planes(cinfo)) { |
+ return false; |
+ } |
// U size and V size have to be the same if we're calling output_raw_data() |
SkISize uvSize = compute_yuv_size(cinfo, 1, kSizeForMemoryAllocation_SizeType); |
SkASSERT(uvSize == compute_yuv_size(cinfo, 2, kSizeForMemoryAllocation_SizeType)); |
@@ -897,8 +908,7 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS |
cinfo.raw_data_out = TRUE; |
if (!planes || !planes[0] || !rowBytes || !rowBytes[0]) { // Compute size only |
- update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_SizeType); |
- return true; |
+ return update_components_sizes(cinfo, componentSizes, kSizeForMemoryAllocation_SizeType); |
} |
set_dct_method(*this, &cinfo); |
@@ -924,7 +934,9 @@ bool SkJPEGImageDecoder::onDecodeYUV8Planes(SkStream* stream, SkISize componentS |
return return_false(cinfo, "output_raw_data"); |
} |
- update_components_sizes(cinfo, componentSizes, kActualSize_SizeType); |
+ if (!update_components_sizes(cinfo, componentSizes, kActualSize_SizeType)) { |
+ return false; |
+ } |
jpeg_finish_decompress(&cinfo); |
if (NULL != colorSpace) { |