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

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

Issue 656673005: Don't read random data in ICO check. (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 | « no previous file | no next file » | 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 alphaBit = 0; 395 alphaBit = 0;
396 #endif 396 #endif
397 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF); 397 int alpha = readByte(buf, xorOffset + 4*pixelNo + 3) & ((alphaBit-1)&0xFF);
398 *address = SkPreMultiplyARGB(alpha, red, green, blue); 398 *address = SkPreMultiplyARGB(alpha, red, green, blue);
399 } 399 }
400 400
401 /////////////////////////////////////////////////////////////////////////////// 401 ///////////////////////////////////////////////////////////////////////////////
402 DEFINE_DECODER_CREATOR(ICOImageDecoder); 402 DEFINE_DECODER_CREATOR(ICOImageDecoder);
403 //////////////////////////////////////////////////////////////////////////////// ///////// 403 //////////////////////////////////////////////////////////////////////////////// /////////
404 404
405 static bool is_ico(SkStreamRewindable* stream) { 405 static bool is_ico(SkStreamRewindable* stream) {
mtklein 2014/10/24 01:59:06 Guh.. I know this is really secondary, but this c
406 // Check to see if the first four bytes are 0,0,1,0 406 // Check to see if the first four bytes are 0,0,1,0
407 // FIXME: Is that required and sufficient? 407 // FIXME: Is that required and sufficient?
408 SkAutoMalloc autoMal(4); 408 SkAutoMalloc autoMal(4);
409 unsigned char* buf = (unsigned char*)autoMal.get(); 409 unsigned char* buf = (unsigned char*)autoMal.get();
410 stream->read((void*)buf, 4); 410 if (stream->read((void*)buf, 4) < 4) {
411 return false;
412 }
411 int reserved = read2Bytes(buf, 0); 413 int reserved = read2Bytes(buf, 0);
412 int type = read2Bytes(buf, 2); 414 int type = read2Bytes(buf, 2);
413 if (reserved != 0 || type != 1) { 415 if (reserved != 0 || type != 1) {
414 // This stream does not represent an ICO image. 416 // This stream does not represent an ICO image.
415 return false; 417 return false;
416 } 418 }
417 return true; 419 return true;
418 } 420 }
419 421
420 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { 422 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) {
421 if (is_ico(stream)) { 423 if (is_ico(stream)) {
422 return SkNEW(SkICOImageDecoder); 424 return SkNEW(SkICOImageDecoder);
423 } 425 }
424 return NULL; 426 return NULL;
425 } 427 }
426 428
427 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); 429 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
428 430
429 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { 431 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
430 if (is_ico(stream)) { 432 if (is_ico(stream)) {
431 return SkImageDecoder::kICO_Format; 433 return SkImageDecoder::kICO_Format;
432 } 434 }
433 return SkImageDecoder::kUnknown_Format; 435 return SkImageDecoder::kUnknown_Format;
434 } 436 }
435 437
436 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); 438 static SkImageDecoder_FormatReg gFormatReg(get_format_ico);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698