Chromium Code Reviews| Index: src/images/SkImageDecoder_libwebp.cpp |
| diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp |
| index 4691d0d13eefd3a419edfd99d75b3f7b8ff9c610..79db23470875ec21609082cf2e8731a3cb5cd59f 100644 |
| --- a/src/images/SkImageDecoder_libwebp.cpp |
| +++ b/src/images/SkImageDecoder_libwebp.cpp |
| @@ -60,16 +60,22 @@ 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 ((size_t)-1 == bytesRead) { |
|
djsollen
2013/08/12 17:54:57
I don't think our stream should ever return -1. I
scroggo
2013/08/12 19:08:10
Done.
|
| + // Could not read any bytes, so we have read the entire stream. |
| + break; |
| + } |
| + bytesToRead -= bytesRead; |
| + totalBytesRead += bytesRead; |
| + SkASSERT(bytesToRead + totalBytesRead == WEBP_VP8_HEADER_SIZE); |
| + } while (!stream->isAtEnd() && bytesToRead > 0); |
|
vikasa
2013/08/12 18:25:41
Assumption here is that 'stream->isAtEnd()' works
djsollen
2013/08/12 18:46:52
Yes, As part of this we are also updating the code
|
| 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 +198,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; |
|
vikasa
2013/08/12 18:25:41
As mentioned by Craig (w.r.t https://codereview.ch
scroggo
2013/08/12 18:44:57
Right. That is why I only check stream->getLength(
|
| SkAutoMalloc srcStorage(readBufferSize); |
| unsigned char* input = (uint8_t*)srcStorage.get(); |
| if (NULL == input) { |