1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/core/SkBitmap.h"
9cb93a386Sopenharmony_ci#include "tests/CodecPriv.h"
10cb93a386Sopenharmony_ci#include "tests/Test.h"
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci// A valid 1x1 indexed PNG.
13cb93a386Sopenharmony_ciunsigned char gPngData[] = {
14cb93a386Sopenharmony_ci  0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
15cb93a386Sopenharmony_ci  0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
16cb93a386Sopenharmony_ci  0x08, 0x03, 0x00, 0x00, 0x00, 0x28, 0xcb, 0x34, 0xbb, 0x00, 0x00, 0x00,
17cb93a386Sopenharmony_ci  0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
18cb93a386Sopenharmony_ci  0x1c, 0x00, 0x0f, 0x01, 0xb9, 0x8f, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c,
19cb93a386Sopenharmony_ci  0x54, 0x45, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0xd2, 0x87, 0xef, 0x71,
20cb93a386Sopenharmony_ci  0x00, 0x00, 0x00, 0x13, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0xfd,
21cb93a386Sopenharmony_ci  0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xf8, 0xaf, 0x16, 0x46, 0x00,
22cb93a386Sopenharmony_ci  0x02, 0x00, 0x01, 0x32, 0x60, 0xf7, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x49,
23cb93a386Sopenharmony_ci  0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
24cb93a386Sopenharmony_ci};
25cb93a386Sopenharmony_ci
26cb93a386Sopenharmony_ci// Attempt to decode an invalid PNG that has a palette. Mostly we're looking to
27cb93a386Sopenharmony_ci// make sure we don't leak memory since libpng uses setjmp for error handling so
28cb93a386Sopenharmony_ci// it's very easy to accidentally skip destructors when a failure happens.
29cb93a386Sopenharmony_ci// As a result, we do not have any REPORTER_ASSERT statements
30cb93a386Sopenharmony_ciDEF_TEST(InvalidIndexedPng, reporter) {
31cb93a386Sopenharmony_ci    SkBitmap image;
32cb93a386Sopenharmony_ci    // Make our PNG invalid by changing a byte.
33cb93a386Sopenharmony_ci    gPngData[sizeof(gPngData) - 1] = 1;
34cb93a386Sopenharmony_ci
35cb93a386Sopenharmony_ci    decode_memory(gPngData, sizeof(gPngData), &image);
36cb93a386Sopenharmony_ci}
37