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

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

Issue 23330002: Avoid getLength in ico decoder. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // In the case of a 4 bit image with an odd width, we need to add some 66 // In the case of a 4 bit image with an odd width, we need to add some
67 // so we can go off the end of the drawn bitmap. 67 // so we can go off the end of the drawn bitmap.
68 // Add 4 to ensure that it is still a multiple of 4. 68 // Add 4 to ensure that it is still a multiple of 4.
69 if (4 == bitCount && (w & 0x1)) { 69 if (4 == bitCount && (w & 0x1)) {
70 return (w + 1) << 2; 70 return (w + 1) << 2;
71 } 71 }
72 // Otherwise return 0, which will allow it to be calculated automatically. 72 // Otherwise return 0, which will allow it to be calculated automatically.
73 return 0; 73 return 0;
74 } 74 }
75 75
76 // Defined in SkImageDecoder.cpp
77 extern size_t copy_stream_to_storage(SkAutoMalloc* storage, SkStream* stream);
78
76 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) 79 bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
77 { 80 {
78 size_t length = stream->getLength(); 81 SkAutoMalloc autoMal;
79 SkAutoMalloc autoMal(length); 82 const size_t length = copy_stream_to_storage(&autoMal, stream);
80 unsigned char* buf = (unsigned char*)autoMal.get(); 83 if (0 == length) {
81 if (stream->read((void*)buf, length) != length) {
82 return false; 84 return false;
83 } 85 }
84 86
87 unsigned char* buf = (unsigned char*)autoMal.get();
88
85 //these should always be the same - should i use for error checking? - what about files that have some 89 //these should always be the same - should i use for error checking? - what about files that have some
86 //incorrect values, but still decode properly? 90 //incorrect values, but still decode properly?
87 int reserved = read2Bytes(buf, 0); // 0 91 int reserved = read2Bytes(buf, 0); // 0
88 int type = read2Bytes(buf, 2); // 1 92 int type = read2Bytes(buf, 2); // 1
89 if (reserved != 0 || type != 1) 93 if (reserved != 0 || type != 1)
90 return false; 94 return false;
91 int count = read2Bytes(buf, 4); 95 int count = read2Bytes(buf, 4);
92 96
93 //need to at least have enough space to hold the initial table of info 97 //need to at least have enough space to hold the initial table of info
94 if (length < (size_t)(6 + count*16)) 98 if (length < (size_t)(6 + count*16))
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory); 414 static SkTRegistry<SkImageDecoder*, SkStream*> gReg(sk_libico_dfactory);
411 415
412 static SkImageDecoder::Format get_format_ico(SkStream* stream) { 416 static SkImageDecoder::Format get_format_ico(SkStream* stream) {
413 if (is_ico(stream)) { 417 if (is_ico(stream)) {
414 return SkImageDecoder::kICO_Format; 418 return SkImageDecoder::kICO_Format;
415 } 419 }
416 return SkImageDecoder::kUnknown_Format; 420 return SkImageDecoder::kUnknown_Format;
417 } 421 }
418 422
419 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico) ; 423 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_ico) ;
OLDNEW
« src/images/SkImageDecoder_libbmp.cpp ('K') | « src/images/SkImageDecoder_libbmp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698