aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/CodecPartialTest.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-07-14 16:32:31 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-14 21:14:06 +0000
commit588fb040b3ad410cdb10c87f9a7884b6eb825e90 (patch)
tree954314604fe306c899e5d44417cc1019a0a078f5 /tests/CodecPartialTest.cpp
parent0274b30feeacae0bcd12f03ae96cb4721c1393a2 (diff)
Report error on failure to create SkCodec
Update NewFromStream to report an error on failure to create an SkCodec, so that a client can distinguish between - not enough data - invalid data In Chromium, this will allow blink::ImageDecoder to call SetFailed if the stream is invalid early and we never create an SkCodec. Without this, ImageDecoder will keep trying to create an SkCodec when it receives more data. Change-Id: I4f505c56d91c982be36a828fd0f7db17b1596588 Reviewed-on: https://skia-review.googlesource.com/22642 Commit-Queue: Leon Scroggins <scroggo@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com> Reviewed-by: Chris Blume <cblume@chromium.org>
Diffstat (limited to 'tests/CodecPartialTest.cpp')
-rw-r--r--tests/CodecPartialTest.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp
index ee012711a6..4a56f46e21 100644
--- a/tests/CodecPartialTest.cpp
+++ b/tests/CodecPartialTest.cpp
@@ -419,3 +419,38 @@ DEF_TEST(Codec_emptyIDAT, r) {
const auto result = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
REPORTER_ASSERT(r, SkCodec::kIncompleteInput == result);
}
+
+DEF_TEST(Codec_incomplete, r) {
+ for (const char* name : { "baby_tux.png",
+ "baby_tux.webp",
+ "CMYK.jpg",
+ "color_wheel.gif",
+ "google_chrome.ico",
+ "rle.bmp",
+ "mandrill.wbmp",
+ }) {
+ sk_sp<SkData> file = GetResourceAsData(name);
+ if (!name) {
+ continue;
+ }
+
+ for (size_t len = 14; len <= file->size(); len += 5) {
+ SkCodec::Result result;
+ auto* stream = new SkMemoryStream(file->data(), len);
+ std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream, &result));
+ if (codec) {
+ if (result != SkCodec::kSuccess) {
+ ERRORF(r, "Created an SkCodec for %s with %lu bytes, but "
+ "reported an error %i", name, len, result);
+ }
+ break;
+ }
+
+ if (SkCodec::kIncompleteInput != result) {
+ ERRORF(r, "Reported error %i for %s with %lu bytes",
+ result, name, len);
+ break;
+ }
+ }
+ }
+}