OLD | NEW |
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 } | 600 } |
601 } else if (*configp != SkBitmap::kRGB_565_Config && | 601 } else if (*configp != SkBitmap::kRGB_565_Config && |
602 *configp != SkBitmap::kARGB_4444_Config) { | 602 *configp != SkBitmap::kARGB_4444_Config) { |
603 *configp = SkBitmap::kARGB_8888_Config; | 603 *configp = SkBitmap::kARGB_8888_Config; |
604 } | 604 } |
605 } | 605 } |
606 } | 606 } |
607 | 607 |
608 // sanity check for size | 608 // sanity check for size |
609 { | 609 { |
610 Sk64 size; | 610 int64_t size = sk_64_mul(origWidth, origHeight); |
611 size.setMul(origWidth, origHeight); | |
612 if (size.isNeg() || !size.is32()) { | |
613 return false; | |
614 } | |
615 // now check that if we are 4-bytes per pixel, we also don't overflow | 611 // now check that if we are 4-bytes per pixel, we also don't overflow |
616 if (size.get32() > (0x7FFFFFFF >> 2)) { | 612 if (size < 0 || size > (0x7FFFFFFF >> 2)) { |
617 return false; | 613 return false; |
618 } | 614 } |
619 } | 615 } |
620 | 616 |
621 if (!this->chooseFromOneChoice(*configp, origWidth, origHeight)) { | 617 if (!this->chooseFromOneChoice(*configp, origWidth, origHeight)) { |
622 return false; | 618 return false; |
623 } | 619 } |
624 | 620 |
625 // If the image has alpha and the decoder wants unpremultiplied | 621 // If the image has alpha and the decoder wants unpremultiplied |
626 // colors, the only supported config is 8888. | 622 // colors, the only supported config is 8888. |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 return SkImageDecoder::kUnknown_Format; | 1288 return SkImageDecoder::kUnknown_Format; |
1293 } | 1289 } |
1294 | 1290 |
1295 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { | 1291 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { |
1296 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; | 1292 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; |
1297 } | 1293 } |
1298 | 1294 |
1299 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); | 1295 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); |
1300 static SkImageDecoder_FormatReg gFormatReg(get_format_png); | 1296 static SkImageDecoder_FormatReg gFormatReg(get_format_png); |
1301 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); | 1297 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); |
OLD | NEW |