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

Unified Diff: src/images/SkImageDecoder_libwebp.cpp

Issue 22841005: Remove dependency on getLength from webp decoder. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Check for eof if no bytes are read. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libwebp.cpp
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index 4691d0d13eefd3a419edfd99d75b3f7b8ff9c610..9f1116e5d5bbbd51c8e168f12d8db99d585f07f6 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -60,16 +60,24 @@ static const size_t WEBP_IDECODE_BUFFER_SZ = (1 << 16);
// Parse headers of RIFF container, and check for valid Webp (VP8) content.
static bool webp_parse_header(SkStream* stream, int* width, int* height, int* alpha) {
unsigned char buffer[WEBP_VP8_HEADER_SIZE];
- const uint32_t contentSize = stream->getLength();
- const size_t len = stream->read(buffer, WEBP_VP8_HEADER_SIZE);
- const uint32_t read_bytes =
- (contentSize < WEBP_VP8_HEADER_SIZE) ? contentSize : WEBP_VP8_HEADER_SIZE;
- if (len != read_bytes) {
- return false; // can't read enough
- }
+ size_t bytesToRead = WEBP_VP8_HEADER_SIZE;
+ size_t totalBytesRead = 0;
+ do {
+ unsigned char* dst = buffer + totalBytesRead;
+ const size_t bytesRead = stream->read(dst, bytesToRead);
+ if (0 == bytesRead) {
+ // Could not read any bytes. Check to see if we are at the end (exit
+ // condition), and continue reading if not. Important for streams
+ // that do not have all the data ready.
+ continue;
+ }
+ bytesToRead -= bytesRead;
+ totalBytesRead += bytesRead;
+ SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE);
+ } while (!stream->isAtEnd() && bytesToRead > 0);
WebPBitstreamFeatures features;
- VP8StatusCode status = WebPGetFeatures(buffer, read_bytes, &features);
+ VP8StatusCode status = WebPGetFeatures(buffer, totalBytesRead, &features);
if (VP8_STATUS_OK != status) {
return false; // Invalid WebP file.
}
@@ -192,9 +200,8 @@ static bool webp_idecode(SkStream* stream, WebPDecoderConfig* config) {
}
stream->rewind();
- const uint32_t contentSize = stream->getLength();
- const uint32_t readBufferSize = (contentSize < WEBP_IDECODE_BUFFER_SZ) ?
- contentSize : WEBP_IDECODE_BUFFER_SZ;
+ const size_t readBufferSize = stream->hasLength() ?
+ SkTMin(stream->getLength(), WEBP_IDECODE_BUFFER_SZ) : WEBP_IDECODE_BUFFER_SZ;
SkAutoMalloc srcStorage(readBufferSize);
unsigned char* input = (uint8_t*)srcStorage.get();
if (NULL == input) {
« 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