aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-09 19:22:00 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-09 19:22:00 +0000
commit80e18c93bbeefe54f8192a380586e6468f179917 (patch)
tree0f33f491bbef05c22ec16fc418e90527e017b27e /src
parenta8797b966f65e73ca462adf94544836e06ce5a03 (diff)
Reland "Make WebP decoding independent of stream length."
This reverts commit 1de924955b103c4f5dc9c46a06527d6a37e6cb70. When reading the stream, only read as much as will fit in the allocated buffer. BUG=skia:1495 Review URL: https://codereview.chromium.org/22629010 git-svn-id: http://skia.googlecode.com/svn/trunk@10665 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/images/SkImageDecoder_libwebp.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index b0fa7f7053..4691d0d13e 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -203,31 +203,26 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) {
return false;
}
- uint32_t bytesRemaining = contentSize;
- while (bytesRemaining > 0) {
- const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ?
- bytesRemaining : WEBP_IDECODE_BUFFER_SZ;
- const size_t bytesRead = stream->read(input, bytesToRead);
+ bool success = true;
+ VP8StatusCode status = VP8_STATUS_SUSPENDED;
+ do {
+ const size_t bytesRead = stream->read(input, readBufferSize);
if (0 == bytesRead) {
+ success = false;
break;
}
- VP8StatusCode status = WebPIAppend(idec, input, bytesRead);
- if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) {
- bytesRemaining -= bytesRead;
- } else {
+ status = WebPIAppend(idec, input, bytesRead);
+ if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) {
+ success = false;
break;
}
- }
+ } while (VP8_STATUS_OK != status);
srcStorage.free();
WebPIDelete(idec);
WebPFreeDecBuffer(&config->output);
- if (bytesRemaining > 0) {
- return false;
- } else {
- return true;
- }
+ return success;
}
static bool webp_get_config_resize(WebPDecoderConfig* config,