From d87fbee77524f83f0eccb7860516d1696e318a96 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 2 Dec 2016 16:47:53 -0500 Subject: Do not create an SkRawCodec with zero dimensions Add a test BUG=skia:3534 BUG=b/33300701 Change-Id: Ifb3a824a36998c5e626c4ad58466845f49d18ebf Reviewed-on: https://skia-review.googlesource.com/5568 Commit-Queue: Leon Scroggins Reviewed-by: Matt Sarett --- resources/empty_images/zero_height.tiff | Bin 0 -> 87460 bytes src/codec/SkRawCodec.cpp | 21 ++++++++------------- tests/CodecTest.cpp | 3 +++ 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 resources/empty_images/zero_height.tiff diff --git a/resources/empty_images/zero_height.tiff b/resources/empty_images/zero_height.tiff new file mode 100644 index 0000000000..ea7a4777af Binary files /dev/null and b/resources/empty_images/zero_height.tiff differ diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index dd86b62230..843ccf0fe5 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -553,7 +553,7 @@ private: return 0x2A == get_endian_short(header + 2, littleEndian); } - void init(int width, int height, const dng_point& cfaPatternSize) { + bool init(int width, int height, const dng_point& cfaPatternSize) { fWidth = width; fHeight = height; @@ -561,6 +561,8 @@ private: // a mosaic info is available. fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0; fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize.h == 6) : false; + + return width > 0 && height > 0; } bool initFromPiex() { @@ -570,15 +572,9 @@ private: if (::piex::IsRaw(&piexStream) && ::piex::GetPreviewImageData(&piexStream, &imageData) == ::piex::Error::kOk) { - // Verify the size information, as it is only optional information for PIEX. - if (imageData.full_width == 0 || imageData.full_height == 0) { - return false; - } - dng_point cfaPatternSize(imageData.cfa_pattern_dim[1], imageData.cfa_pattern_dim[0]); - this->init(static_cast(imageData.full_width), - static_cast(imageData.full_height), cfaPatternSize); - return true; + return this->init(static_cast(imageData.full_width), + static_cast(imageData.full_height), cfaPatternSize); } return false; } @@ -606,10 +602,9 @@ private: if (fNegative->GetMosaicInfo() != nullptr) { cfaPatternSize = fNegative->GetMosaicInfo()->fCFAPatternSize; } - this->init(static_cast(fNegative->DefaultCropSizeH().As_real64()), - static_cast(fNegative->DefaultCropSizeV().As_real64()), - cfaPatternSize); - return true; + return this->init(static_cast(fNegative->DefaultCropSizeH().As_real64()), + static_cast(fNegative->DefaultCropSizeV().As_real64()), + cfaPatternSize); } catch (...) { return false; } diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp index d15c710325..dd969960dc 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -648,6 +648,9 @@ DEF_TEST(Codec_Empty, r) { test_invalid(r, "empty_images/zero-height.wbmp"); // This image is an ico with an embedded mask-bmp. This is illegal. test_invalid(r, "invalid_images/mask-bmp-ico.ico"); +#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) + test_invalid(r, "empty_images/zero_height.tiff"); +#endif } static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) { -- cgit v1.2.3