| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010, The Android Open Source Project | 2 * Copyright 2010, The Android Open Source Project |
| 3 * | 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
| 7 * | 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * | 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features); | 73 VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features); |
| 74 if (VP8_STATUS_OK != status) { | 74 if (VP8_STATUS_OK != status) { |
| 75 return false; // Invalid WebP file. | 75 return false; // Invalid WebP file. |
| 76 } | 76 } |
| 77 *width = features.width; | 77 *width = features.width; |
| 78 *height = features.height; | 78 *height = features.height; |
| 79 *alpha = features.has_alpha; | 79 *alpha = features.has_alpha; |
| 80 | 80 |
| 81 // sanity check for image size that's about to be decoded. | 81 // sanity check for image size that's about to be decoded. |
| 82 { | 82 { |
| 83 int64_t size = sk_64_mul(*width, *height); | 83 Sk64 size; |
| 84 if (!sk_64_isS32(size)) { | 84 size.setMul(*width, *height); |
| 85 if (size.isNeg() || !size.is32()) { |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 // now check that if we are 4-bytes per pixel, we also don't overflow | 88 // now check that if we are 4-bytes per pixel, we also don't overflow |
| 88 if (sk_64_asS32(size) > (0x7FFFFFFF >> 2)) { | 89 if (size.get32() > (0x7FFFFFFF >> 2)) { |
| 89 return false; | 90 return false; |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 return true; | 93 return true; |
| 93 } | 94 } |
| 94 | 95 |
| 95 class SkWEBPImageDecoder: public SkImageDecoder { | 96 class SkWEBPImageDecoder: public SkImageDecoder { |
| 96 public: | 97 public: |
| 97 SkWEBPImageDecoder() { | 98 SkWEBPImageDecoder() { |
| 98 fInputStream = NULL; | 99 fInputStream = NULL; |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return SkImageDecoder::kUnknown_Format; | 596 return SkImageDecoder::kUnknown_Format; |
| 596 } | 597 } |
| 597 | 598 |
| 598 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { | 599 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { |
| 599 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; | 600 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL
L; |
| 600 } | 601 } |
| 601 | 602 |
| 602 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); | 603 static SkImageDecoder_DecodeReg gDReg(sk_libwebp_dfactory); |
| 603 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); | 604 static SkImageDecoder_FormatReg gFormatReg(get_format_webp); |
| 604 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); | 605 static SkImageEncoder_EncodeReg gEReg(sk_libwebp_efactory); |
| OLD | NEW |