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 |