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 "include/core/SkCanvas.h"
10cb93a386Sopenharmony_ci#include "include/core/SkImageInfo.h"
11cb93a386Sopenharmony_ci#include "include/core/SkSurface.h"
12cb93a386Sopenharmony_ci#include "tests/CodecPriv.h"
13cb93a386Sopenharmony_ci#include "tests/Test.h"
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci// A 20x1 image with 8 bits per pixel and a palette size of 2. Pixel values are 255, 254... Run
16cb93a386Sopenharmony_ci// this test with ASAN to make sure we don't try to access before/after any palette-sized buffers.
17cb93a386Sopenharmony_ciunsigned char gPng[] = {
18cb93a386Sopenharmony_ci    0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
19cb93a386Sopenharmony_ci    0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
20cb93a386Sopenharmony_ci    0x08, 0x03, 0x00, 0x00, 0x00, 0xe9, 0x4c, 0x7e, 0x17, 0x00, 0x00, 0x00,
21cb93a386Sopenharmony_ci    0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
22cb93a386Sopenharmony_ci    0x1c, 0x00, 0x0f, 0x01, 0xb9, 0x8f, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c,
23cb93a386Sopenharmony_ci    0x54, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x67, 0xb9, 0xcf,
24cb93a386Sopenharmony_ci    0x00, 0x00, 0x00, 0x20, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0xfd,
25cb93a386Sopenharmony_ci    0x07, 0x01, 0x00, 0x20, 0x08, 0x00, 0x41, 0xbc, 0x5b, 0xe8, 0xdf, 0x97,
26cb93a386Sopenharmony_ci    0x99, 0xe3, 0x92, 0xa0, 0xf2, 0xdf, 0x3d, 0x7b, 0x0d, 0xda, 0x04, 0x1c,
27cb93a386Sopenharmony_ci    0x03, 0xad, 0x00, 0x38, 0x5c, 0x2e, 0xad, 0x12, 0x00, 0x00, 0x00, 0x00,
28cb93a386Sopenharmony_ci    0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
29cb93a386Sopenharmony_ci};
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ciDEF_TEST(IndexedPngOverflow, reporter) {
32cb93a386Sopenharmony_ci    SkBitmap bm;
33cb93a386Sopenharmony_ci    bool success = decode_memory(gPng, sizeof(gPng), &bm);
34cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, success);
35cb93a386Sopenharmony_ci
36cb93a386Sopenharmony_ci    SkSurface::MakeRasterN32Premul(20, 1)->getCanvas()->drawImage(bm.asImage(), 0, 0);
37cb93a386Sopenharmony_ci}
38