Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 // SkPNGImageDecoder is not available on all platforms. | |
| 9 #if !defined(SK_BUILD_FOR_MAC) && \ | |
| 10 !defined(SK_BUILD_FOR_WIN) && \ | |
|
scroggo
2015/03/11 21:01:32
It turns out we cannot depend on this build flag.
David Lattimore
2015/03/11 21:47:21
I've changed it so that it only runs on UNIX. Does
scroggo
2015/03/12 14:13:01
Probably... Android is the main place we care, and
| |
| 11 !defined(SK_BUILD_FOR_IOS) | |
| 12 | |
| 13 #include "SkBitmap.h" | |
| 14 #include "SkCanvas.h" | |
| 15 #include "SkForceLinking.h" | |
| 16 #include "SkImageDecoder.h" | |
| 17 #include "SkImageInfo.h" | |
| 18 #include "SkSurface.h" | |
| 19 #include "Test.h" | |
| 20 | |
| 21 // A 20x1 image with 8 bits per pixel and a palette size of 2. Pixel values are 255, 254... Run | |
| 22 // this test with ASAN to make sure we don't try to access before/after any pale tte-sized buffers. | |
| 23 unsigned char gPng[] = { | |
| 24 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, | |
| 25 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, | |
| 26 0x08, 0x03, 0x00, 0x00, 0x00, 0xe9, 0x4c, 0x7e, 0x17, 0x00, 0x00, 0x00, | |
| 27 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, | |
| 28 0x1c, 0x00, 0x0f, 0x01, 0xb9, 0x8f, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c, | |
| 29 0x54, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x67, 0xb9, 0xcf, | |
| 30 0x00, 0x00, 0x00, 0x20, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0xfd, | |
| 31 0x07, 0x01, 0x00, 0x20, 0x08, 0x00, 0x41, 0xbc, 0x5b, 0xe8, 0xdf, 0x97, | |
| 32 0x99, 0xe3, 0x92, 0xa0, 0xf2, 0xdf, 0x3d, 0x7b, 0x0d, 0xda, 0x04, 0x1c, | |
| 33 0x03, 0xad, 0x00, 0x38, 0x5c, 0x2e, 0xad, 0x12, 0x00, 0x00, 0x00, 0x00, | |
| 34 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 | |
| 35 }; | |
| 36 | |
| 37 DEF_TEST(IndexedPngOverflow, reporter) { | |
| 38 SkBitmap image; | |
|
scroggo
2015/03/11 21:01:32
nit: Skia uses 4 space indent.
David Lattimore
2015/03/11 21:47:21
Done.
| |
| 39 SkForceLinking(false); | |
| 40 bool success = SkImageDecoder::DecodeMemory( | |
| 41 gPng, sizeof(gPng), &image, SkColorType::kUnknown_SkColorType, | |
| 42 SkImageDecoder::kDecodePixels_Mode); | |
| 43 REPORTER_ASSERT(reporter, success); | |
| 44 | |
| 45 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(SkImageInfo::MakeN32Premu l(20, 1))); | |
| 46 SkCanvas* canvas = surface->getCanvas(); | |
| 47 SkRect destRect = SkRect::MakeXYWH(0, 0, 20, 1); | |
| 48 canvas->drawBitmapRect(image, destRect, NULL); | |
| 49 } | |
| 50 | |
| 51 #endif // !(SK_BUILD_FOR_MAC||SK_BUILD_FOR_WIN||SK_BUILD_FOR_IOS) | |
| OLD | NEW |