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

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: Respond to comments. Created 6 years, 2 months 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
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 char buf[4];
409 unsigned char* buf = (unsigned char*)autoMal.get(); 409 if (stream->read((void*)buf, 4) != 4) {
410 stream->read((void*)buf, 4); 410 return false;
411 }
411 int reserved = read2Bytes(buf, 0); 412 int reserved = read2Bytes(buf, 0);
412 int type = read2Bytes(buf, 2); 413 int type = read2Bytes(buf, 2);
413 if (reserved != 0 || type != 1) { 414 return 0 == reserved && 1 == type;
414 // This stream does not represent an ICO image.
415 return false;
416 }
417 return true;
418 } 415 }
419 416
420 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) { 417 static SkImageDecoder* sk_libico_dfactory(SkStreamRewindable* stream) {
421 if (is_ico(stream)) { 418 if (is_ico(stream)) {
422 return SkNEW(SkICOImageDecoder); 419 return SkNEW(SkICOImageDecoder);
423 } 420 }
424 return NULL; 421 return NULL;
425 } 422 }
426 423
427 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory); 424 static SkImageDecoder_DecodeReg gReg(sk_libico_dfactory);
428 425
429 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) { 426 static SkImageDecoder::Format get_format_ico(SkStreamRewindable* stream) {
430 if (is_ico(stream)) { 427 if (is_ico(stream)) {
431 return SkImageDecoder::kICO_Format; 428 return SkImageDecoder::kICO_Format;
432 } 429 }
433 return SkImageDecoder::kUnknown_Format; 430 return SkImageDecoder::kUnknown_Format;
434 } 431 }
435 432
436 static SkImageDecoder_FormatReg gFormatReg(get_format_ico); 433 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