Index: Source/platform/image-decoders/FastSharedBufferReaderTest.cpp |
diff --git a/Source/platform/image-decoders/FastSharedBufferReaderTest.cpp b/Source/platform/image-decoders/FastSharedBufferReaderTest.cpp |
index 2a989f9b0e7e1e8cdf40a78a3119e92f32a20fb0..3479ac1fa674566982f114a7f3ef4756b2600170 100644 |
--- a/Source/platform/image-decoders/FastSharedBufferReaderTest.cpp |
+++ b/Source/platform/image-decoders/FastSharedBufferReaderTest.cpp |
@@ -38,6 +38,8 @@ namespace blink { |
namespace { |
+const unsigned kDefaultTestSize = 4 * SharedBuffer::kSegmentSize; |
+ |
void prepareReferenceData(char* buffer, size_t size) |
{ |
for (size_t i = 0; i < size; ++i) |
@@ -48,8 +50,7 @@ void prepareReferenceData(char* buffer, size_t size) |
TEST(FastSharedBufferReaderTest, nonSequentialReads) |
{ |
- // This is 4 times SharedBuffer's segment size. |
- char referenceData[16384]; |
+ char referenceData[kDefaultTestSize]; |
prepareReferenceData(referenceData, sizeof(referenceData)); |
RefPtr<SharedBuffer> data = SharedBuffer::create(); |
data->append(referenceData, sizeof(referenceData)); |
@@ -68,8 +69,7 @@ TEST(FastSharedBufferReaderTest, nonSequentialReads) |
TEST(FastSharedBufferReaderTest, readBackwards) |
{ |
- // This is 4 times SharedBuffer's segment size. |
- char referenceData[16384]; |
+ char referenceData[kDefaultTestSize]; |
prepareReferenceData(referenceData, sizeof(referenceData)); |
RefPtr<SharedBuffer> data = SharedBuffer::create(); |
data->append(referenceData, sizeof(referenceData)); |
@@ -88,8 +88,7 @@ TEST(FastSharedBufferReaderTest, readBackwards) |
TEST(FastSharedBufferReaderTest, byteByByte) |
{ |
- // This is 4 times SharedBuffer's segment size. |
- char referenceData[16384]; |
+ char referenceData[kDefaultTestSize]; |
prepareReferenceData(referenceData, sizeof(referenceData)); |
RefPtr<SharedBuffer> data = SharedBuffer::create(); |
data->append(referenceData, sizeof(referenceData)); |
@@ -100,4 +99,21 @@ TEST(FastSharedBufferReaderTest, byteByByte) |
} |
} |
+// Tests that a read from inside the penultimate segment to the very end of the |
+// buffer doesn't try to read off the end of the buffer. |
+TEST(FastSharedBufferReaderTest, readAllOverlappingLastSegmentBoundary) |
+{ |
+ const unsigned dataSize = 2 * SharedBuffer::kSegmentSize; |
+ char referenceData[dataSize]; |
+ prepareReferenceData(referenceData, dataSize); |
+ RefPtr<SharedBuffer> data = SharedBuffer::create(); |
+ data->append(referenceData, dataSize); |
+ |
+ char buffer[dataSize]; |
+ FastSharedBufferReader reader(data); |
+ reader.getConsecutiveData(0, dataSize, buffer); |
+ |
+ ASSERT_FALSE(memcmp(buffer, referenceData, dataSize)); |
+} |
+ |
} // namespace blink |