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

Unified Diff: Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp

Issue 1358643002: Fix caching bug in JPEGImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Respond to pkasting's comments in patch set 1 Created 5 years, 3 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 | « Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
diff --git a/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp b/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
index 59ae3c81f2557edeef572f0a271593353c66cf7b..514ebcf24035046ee73f3c5be5a4bf4faa782ca8 100644
--- a/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
+++ b/Source/platform/image-decoders/jpeg/JPEGImageDecoderTest.cpp
@@ -240,4 +240,48 @@ TEST(JPEGImageDecoderTest, byteByByte)
testByteByByteDecode(&createDecoder, "/LayoutTests/fast/images/resources/red-at-12-oclock-with-color-profile.jpg", 1u, cAnimationNone);
}
+static unsigned createDecodingBaseline(SharedBuffer* data)
+{
+ OwnPtr<ImageDecoder> decoder = createDecoder();
+ decoder->setData(data, true);
+ ImageFrame* frame = decoder->frameBufferAtIndex(0);
+ return hashBitmap(frame->bitmap());
+}
+
+// This test verifies that calling SharedBuffer::mergeSegmentsIntoBuffer() does
+// not break JPEG decoding at a critical point: in between a call to decode the
+// size (when JPEGImageDecoder stops while it may still have input data to
+// read) and a call to do a full decode.
+TEST(JPEGImageDecoderTest, mergeBuffer)
+{
+ const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg";
+ RefPtr<SharedBuffer> data = readFile(jpegFile);
+ ASSERT_TRUE(data);
+
+ const unsigned hash = createDecodingBaseline(data.get());
+
+ // In order to do any verification, this test needs to move the data owned
+ // by the SharedBuffer. A way to guarantee that is to create a new one, and
+ // then append a string of characters greater than kSegmentSize. This
+ // results in writing the data into a segment, skipping the internal
+ // contiguous buffer.
+ RefPtr<SharedBuffer> segmentedData = SharedBuffer::create();
+ segmentedData->append(data->data(), data->size());
+
+ OwnPtr<ImageDecoder> decoder = createDecoder();
+ decoder->setData(segmentedData.get(), true);
+
+ ASSERT_TRUE(decoder->isSizeAvailable());
+
+ // This will call SharedBuffer::mergeSegmentsIntoBuffer, copying all
+ // segments into the contiguous buffer. If JPEGImageDecoder was pointing to
+ // data in a segment, its pointer would no longer be valid.
+ segmentedData->data();
+
+ ImageFrame* frame = decoder->frameBufferAtIndex(0);
+ ASSERT_FALSE(decoder->failed());
+ EXPECT_EQ(frame->status(), ImageFrame::FrameComplete);
+ EXPECT_EQ(hashBitmap(frame->bitmap()), hash);
+}
+
} // namespace blink
« no previous file with comments | « Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698