Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: src/images/SkImageDecoder_libico.cpp

Issue 712123002: Add tests (and fix!) for known bad ICO files. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « resources/invalid_images/sigsegv_favicon_2.ico ('k') | tests/BadIcoTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 //otherwise, they could be used for error checking 152 //otherwise, they could be used for error checking
153 int w = readByte(buf, 6 + choice*16); 153 int w = readByte(buf, 6 + choice*16);
154 int h = readByte(buf, 7 + choice*16); 154 int h = readByte(buf, 7 + choice*16);
155 int colorCount = readByte(buf, 8 + choice*16); 155 int colorCount = readByte(buf, 8 + choice*16);
156 //int reservedToo = readByte(buf, 9 + choice*16); //0 156 //int reservedToo = readByte(buf, 9 + choice*16); //0
157 //int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0 157 //int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0
158 //int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usu ally 0 158 //int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usu ally 0
159 const size_t size = read4Bytes(buf, 14 + choice*16); //matters? 159 const size_t size = read4Bytes(buf, 14 + choice*16); //matters?
160 const size_t offset = read4Bytes(buf, 18 + choice*16); 160 const size_t offset = read4Bytes(buf, 18 + choice*16);
161 // promote the sum to 64-bits to avoid overflow 161 // promote the sum to 64-bits to avoid overflow
162 if (((uint64_t)offset + size) > length) { 162 if (offset > length || size > length || ((uint64_t)offset + size) > length) {
163 return kFailure; 163 return kFailure;
164 } 164 }
165 165
166 // Check to see if this is a PNG image inside the ICO 166 // Check to see if this is a PNG image inside the ICO
167 { 167 {
168 SkMemoryStream subStream(buf + offset, size, false); 168 SkMemoryStream subStream(buf + offset, size, false);
169 SkAutoTDelete<SkImageDecoder> otherDecoder(SkImageDecoder::Factory(&subS tream)); 169 SkAutoTDelete<SkImageDecoder> otherDecoder(SkImageDecoder::Factory(&subS tream));
170 if (otherDecoder.get() != NULL) { 170 if (otherDecoder.get() != NULL) {
171 // Disallow nesting ICO files within one another 171 // Disallow nesting ICO files within one another
172 // FIXME: Can ICO files contain other formats besides PNG? 172 // FIXME: Can ICO files contain other formats besides PNG?
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); 424 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
425 425
426 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { 426 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
427 if (is_ico(stream)) { 427 if (is_ico(stream)) {
428 return SkImageDecoder::kICO_Format; 428 return SkImageDecoder::kICO_Format;
429 } 429 }
430 return SkImageDecoder::kUnknown_Format; 430 return SkImageDecoder::kUnknown_Format;
431 } 431 }
432 432
433 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); 433 static SkImageDecoder_FormatReg gFormatReg(get_format_ico);
OLDNEW
« no previous file with comments | « resources/invalid_images/sigsegv_favicon_2.ico ('k') | tests/BadIcoTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698