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

Side by Side Diff: Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp

Issue 15914009: More tolerant about malformed GIF files (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: comments Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 TEST(GIFImageDecoderTest, brokenSecondFrame) 181 TEST(GIFImageDecoderTest, brokenSecondFrame)
182 { 182 {
183 OwnPtr<GIFImageDecoder> decoder(createDecoder()); 183 OwnPtr<GIFImageDecoder> decoder(createDecoder());
184 184
185 RefPtr<SharedBuffer> data = readFile("/Source/WebKit/chromium/tests/data/bro ken.gif"); 185 RefPtr<SharedBuffer> data = readFile("/Source/WebKit/chromium/tests/data/bro ken.gif");
186 ASSERT_TRUE(data.get()); 186 ASSERT_TRUE(data.get());
187 decoder->setData(data.get(), true); 187 decoder->setData(data.get(), true);
188 188
189 EXPECT_EQ(0u, decoder->frameCount()); 189 // One frame is detected but cannot be decoded.
190 ImageFrame* frame = decoder->frameBufferAtIndex(0); 190 EXPECT_EQ(1u, decoder->frameCount());
191 ImageFrame* frame = decoder->frameBufferAtIndex(1);
191 EXPECT_FALSE(frame); 192 EXPECT_FALSE(frame);
192 EXPECT_EQ(cAnimationLoopOnce, decoder->repetitionCount());
193 } 193 }
194 194
195 TEST(GIFImageDecoderTest, progressiveDecode) 195 TEST(GIFImageDecoderTest, progressiveDecode)
196 { 196 {
197 RefPtr<SharedBuffer> fullData = readFile("/Source/WebKit/chromium/tests/data /radient.gif"); 197 RefPtr<SharedBuffer> fullData = readFile("/Source/WebKit/chromium/tests/data /radient.gif");
198 ASSERT_TRUE(fullData.get()); 198 ASSERT_TRUE(fullData.get());
199 const size_t fullLength = fullData->size(); 199 const size_t fullLength = fullData->size();
200 200
201 OwnPtr<GIFImageDecoder> decoder; 201 OwnPtr<GIFImageDecoder> decoder;
202 ImageFrame* frame; 202 ImageFrame* frame;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 EXPECT_FALSE(decoder->failed()); 290 EXPECT_FALSE(decoder->failed());
291 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(0)); 291 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(0));
292 EXPECT_FALSE(decoder->frameIsCompleteAtIndex(1)); 292 EXPECT_FALSE(decoder->frameIsCompleteAtIndex(1));
293 293
294 decoder->setData(data.get(), true); 294 decoder->setData(data.get(), true);
295 EXPECT_EQ(2u, decoder->frameCount()); 295 EXPECT_EQ(2u, decoder->frameCount());
296 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(0)); 296 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(0));
297 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(1)); 297 EXPECT_TRUE(decoder->frameIsCompleteAtIndex(1));
298 } 298 }
299 299
300 TEST(GIFImageDecoderTest, badImageSeparator)
301 {
302 RefPtr<SharedBuffer> fullData = readFile("/LayoutTests/fast/images/resources /animated.gif");
303 ASSERT_TRUE(fullData.get());
304 const size_t fullLength = fullData->size();
305
306 OwnPtr<GIFImageDecoder> decoder(createDecoder());
307 decoder->setData(fullData.get(), true);
308 EXPECT_EQ(2u, decoder->frameCount());
309 ImageFrame* frame = decoder->frameBufferAtIndex(0);
310 ASSERT_TRUE(frame);
311 EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
312 const unsigned referenceHash = hashSkBitmap(frame->getSkBitmap());
313
314 // Replace the second image separator with an invalid character.
315 RefPtr<SharedBuffer> badData = SharedBuffer::create();
316 int count = 0;
317 for (size_t i = 0; i < fullLength; ++i) {
318 if (fullData->data()[i] == ',') {
319 if (count++ == 1) {
Peter Kasting 2013/05/29 04:30:17 Nit: I think "if (++count == 2)" is slightly clear
Alpha Left Google 2013/05/29 19:38:58 Done. SharedBuffer return const char* so a copy is
Peter Kasting 2013/05/29 20:02:53 Why? A file to test this could be a few hundred b
320 badData->append("=", 1);
321 continue;
322 }
323 }
324 badData->append(fullData->data() + i, 1);
325 }
326
327 decoder = createDecoder();
328 decoder->setData(badData.get(), true);
329 EXPECT_EQ(1u, decoder->frameCount());
330 frame = decoder->frameBufferAtIndex(0);
331 ASSERT_TRUE(frame);
332 EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
333 const unsigned hash = hashSkBitmap(frame->getSkBitmap());
334
335 EXPECT_EQ(referenceHash, hash);
336 }
337
300 #endif 338 #endif
301 339
302 } // namespace 340 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698