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

Side by Side Diff: src/codec/SkBmpCodec.cpp

Issue 1498923002: Fix overflow caught by ASAN. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years 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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkBmpMaskCodec.h" 9 #include "SkBmpMaskCodec.h"
10 #include "SkBmpRLECodec.h" 10 #include "SkBmpRLECodec.h"
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 SkASSERT(SkCodec::kBottomUp_SkScanlineOrder == fRowOrder); 547 SkASSERT(SkCodec::kBottomUp_SkScanlineOrder == fRowOrder);
548 return height - y - 1; 548 return height - y - 1;
549 } 549 }
550 550
551 /* 551 /*
552 * Compute the number of colors in the color table 552 * Compute the number of colors in the color table
553 */ 553 */
554 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) { 554 uint32_t SkBmpCodec::computeNumColors(uint32_t numColors) {
555 // Zero is a default for maxColors 555 // Zero is a default for maxColors
556 // Also set numColors to maxColors when it is too large 556 // Also set numColors to maxColors when it is too large
557 uint32_t maxColors = 1 << fBitsPerPixel; 557 uint32_t maxColors = fBitsPerPixel >= 32 ? UINT32_MAX : 1 << fBitsPerPixel;
msarett 2015/12/03 20:55:22 Can we use 0 instead of UINT32_MAX? While you're
558 if (numColors == 0 || numColors >= maxColors) { 558 if (numColors == 0 || numColors >= maxColors) {
559 return maxColors; 559 return maxColors;
560 } 560 }
561 return numColors; 561 return numColors;
562 } 562 }
563 563
564 SkCodec::Result SkBmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, 564 SkCodec::Result SkBmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
565 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { 565 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
566 if (!conversion_possible(dstInfo, this->getInfo())) { 566 if (!conversion_possible(dstInfo, this->getInfo())) {
567 SkCodecPrintf("Error: cannot convert input type to output type.\n"); 567 SkCodecPrintf("Error: cannot convert input type to output type.\n");
568 return kInvalidConversion; 568 return kInvalidConversion;
569 } 569 }
570 570
571 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount); 571 return prepareToDecode(dstInfo, options, inputColorPtr, inputColorCount);
572 } 572 }
573 573
574 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { 574 int SkBmpCodec::onGetScanlines(void* dst, int count, size_t rowBytes) {
575 // Create a new image info representing the portion of the image to decode 575 // Create a new image info representing the portion of the image to decode
576 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count) ; 576 SkImageInfo rowInfo = this->dstInfo().makeWH(this->dstInfo().width(), count) ;
577 577
578 // Decode the requested rows 578 // Decode the requested rows
579 return this->decodeRows(rowInfo, dst, rowBytes, this->options()); 579 return this->decodeRows(rowInfo, dst, rowBytes, this->options());
580 } 580 }
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