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

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

Issue 22629010: Reland "Make WebP decoding independent of stream length." (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Change from the original merge. 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
« 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 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const uint32_t readBufferSize = (contentSize < WEBP_IDECODE_BUFFER_SZ) ? 196 const uint32_t readBufferSize = (contentSize < WEBP_IDECODE_BUFFER_SZ) ?
197 contentSize : WEBP_IDECODE_BUFFER_SZ; 197 contentSize : WEBP_IDECODE_BUFFER_SZ;
198 SkAutoMalloc srcStorage(readBufferSize); 198 SkAutoMalloc srcStorage(readBufferSize);
199 unsigned char* input = (uint8_t*)srcStorage.get(); 199 unsigned char* input = (uint8_t*)srcStorage.get();
200 if (NULL == input) { 200 if (NULL == input) {
201 WebPIDelete(idec); 201 WebPIDelete(idec);
202 WebPFreeDecBuffer(&config->output); 202 WebPFreeDecBuffer(&config->output);
203 return false; 203 return false;
204 } 204 }
205 205
206 uint32_t bytesRemaining = contentSize; 206 bool success = true;
207 while (bytesRemaining > 0) { 207 VP8StatusCode status = VP8_STATUS_SUSPENDED;
208 const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ? 208 do {
209 bytesRemaining : WEBP_IDECODE_BUFFER_SZ; 209 const size_t bytesRead = stream->read(input, readBufferSize);
scroggo 2013/08/09 19:15:32 Patch set 2 has the fix - don't write beyond the s
210 const size_t bytesRead = stream->read(input, bytesToRead);
211 if (0 == bytesRead) { 210 if (0 == bytesRead) {
211 success = false;
212 break; 212 break;
213 } 213 }
214 214
215 VP8StatusCode status = WebPIAppend(idec, input, bytesRead); 215 status = WebPIAppend(idec, input, bytesRead);
216 if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) { 216 if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) {
217 bytesRemaining -= bytesRead; 217 success = false;
218 } else {
219 break; 218 break;
220 } 219 }
221 } 220 } while (VP8_STATUS_OK != status);
222 srcStorage.free(); 221 srcStorage.free();
223 WebPIDelete(idec); 222 WebPIDelete(idec);
224 WebPFreeDecBuffer(&config->output); 223 WebPFreeDecBuffer(&config->output);
225 224
226 if (bytesRemaining > 0) { 225 return success;
227 return false;
228 } else {
229 return true;
230 }
231 } 226 }
232 227
233 static bool webp_get_config_resize(WebPDecoderConfig* config, 228 static bool webp_get_config_resize(WebPDecoderConfig* config,
234 SkBitmap* decodedBitmap, 229 SkBitmap* decodedBitmap,
235 int width, int height, bool premultiply) { 230 int width, int height, bool premultiply) {
236 WEBP_CSP_MODE mode = webp_decode_mode(decodedBitmap, premultiply); 231 WEBP_CSP_MODE mode = webp_decode_mode(decodedBitmap, premultiply);
237 if (MODE_LAST == mode) { 232 if (MODE_LAST == mode) {
238 return false; 233 return false;
239 } 234 }
240 235
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 return SkImageDecoder::kUnknown_Format; 588 return SkImageDecoder::kUnknown_Format;
594 } 589 }
595 590
596 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) { 591 static SkImageEncoder* sk_libwebp_efactory(SkImageEncoder::Type t) {
597 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L; 592 return (SkImageEncoder::kWEBP_Type == t) ? SkNEW(SkWEBPImageEncoder) : NUL L;
598 } 593 }
599 594
600 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory); 595 static SkTRegistry<SkImageDecoder*, SkStream*> gDReg(sk_libwebp_dfactory);
601 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp ); 596 static SkTRegistry<SkImageDecoder::Format, SkStream*> gFormatReg(get_format_webp );
602 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact ory); 597 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_libwebp_efact ory);
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