Skip to content

Commit 3e9f006

Browse files
LeonScrogginsandi34
authored andcommitted
Handle bad ICO data better.
Cherry-pick from 57ad493 in Skia: Interpret size and offset as size_t, as they should be. When read as int, they could be negative values. If they are negative (rather than positive and very large), they will not allow us to fail the length test, resulting in trying to read uninitialized memory. BUG=b/16010240 R=halcanary@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/374413005 BUG:16010240 Change-Id: I70ff31c1d06ea2705700bb9f5c767a100b946d09
1 parent ae64a20 commit 3e9f006

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/images/SkImageDecoder_libico.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
148148
//int reservedToo = readByte(buf, 9 + choice*16); //0
149149
//int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0
150150
//int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usually 0
151-
int size = read4Bytes(buf, 14 + choice*16); //matters?
152-
int offset = read4Bytes(buf, 18 + choice*16);
153-
if ((size_t)(offset + size) > length)
151+
const size_t size = read4Bytes(buf, 14 + choice*16); //matters?
152+
const size_t offset = read4Bytes(buf, 18 + choice*16);
153+
if ((offset + size) > length) {
154154
return false;
155+
}
155156

156157
// Check to see if this is a PNG image inside the ICO
157158
{

0 commit comments

Comments
 (0)