diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-04-24 09:32:50 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-24 14:02:15 +0000 |
commit | b644650e091c86cfadff0fbc2a83ee5ca35a735f (patch) | |
tree | 5a6685e956aa359b19bbfa1fe4b8f4e846377d6a /src/codec/SkPngCodec.cpp | |
parent | df2bf213649e0b2bcb9402548af9976bbdf7a218 (diff) |
Fix decoding incomplete PNG images
If process_data is unable to read (and therefore process) as many bytes
as it expects, process the bytes read before returning false.
Fixes differences in Gold.
Add a test that verifies that it is okay to call png_process_data with
0 bytes. (We could special case 0, but libpng already checks for 0.)
Change-Id: Id500b9305ee3bb6a1a7e8fc70d4e723cb4742b55
Reviewed-on: https://skia-review.googlesource.com/14144
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/codec/SkPngCodec.cpp')
-rw-r--r-- | src/codec/SkPngCodec.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index 6b6ac99f57..1f69159ee6 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -132,10 +132,11 @@ static inline bool process_data(png_structp png_ptr, png_infop info_ptr, SkStream* stream, void* buffer, size_t bufferSize, size_t length) { while (length > 0) { const size_t bytesToProcess = std::min(bufferSize, length); - if (stream->read(buffer, bytesToProcess) < bytesToProcess) { + const size_t bytesRead = stream->read(buffer, bytesToProcess); + png_process_data(png_ptr, info_ptr, (png_bytep) buffer, bytesRead); + if (bytesRead < bytesToProcess) { return false; } - png_process_data(png_ptr, info_ptr, (png_bytep) buffer, bytesToProcess); length -= bytesToProcess; } return true; |