OLD | NEW |
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 Loading... |
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 Loading... |
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); |
OLD | NEW |