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

Unified Diff: Source/platform/image-decoders/FastSharedBufferReader.cpp

Issue 1011113003: Fix potential bug in FastSharedBufferReader::getConsecutiveData (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: back to v6 plus define Created 5 years, 8 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
Index: Source/platform/image-decoders/FastSharedBufferReader.cpp
diff --git a/Source/platform/image-decoders/FastSharedBufferReader.cpp b/Source/platform/image-decoders/FastSharedBufferReader.cpp
index 4475960fdcb4a12dab70112a482d779630b558e4..3eac7cf1844447158d1351a97bc5d3e01b975128 100644
--- a/Source/platform/image-decoders/FastSharedBufferReader.cpp
+++ b/Source/platform/image-decoders/FastSharedBufferReader.cpp
@@ -50,32 +50,35 @@ const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size
return m_segment + dataPosition - m_dataPosition;
// Return a pointer into |m_data| if the request doesn't span segments.
- m_dataPosition = dataPosition;
- m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition);
- ASSERT(m_segmentLength);
+ getSomeDataInternal(dataPosition);
if (length <= m_segmentLength)
return m_segment;
- for (char* tempBuffer = buffer; length;) {
+ for (char* dest = buffer; ; ) {
size_t copy = std::min(length, m_segmentLength);
- memcpy(tempBuffer, m_segment, copy);
- m_dataPosition += copy;
+ memcpy(dest, m_segment, copy);
length -= copy;
- tempBuffer += copy;
+ if (!length)
+ return buffer;
- m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition);
- ASSERT(m_segmentLength);
+ // Continue reading the next segment.
+ dest += copy;
+ getSomeDataInternal(m_dataPosition + copy);
}
- return buffer;
}
size_t FastSharedBufferReader::getSomeData(const char*& someData, size_t dataPosition)
{
- m_segmentLength = m_data->getSomeData(m_segment, dataPosition);
+ getSomeDataInternal(dataPosition);
someData = m_segment;
+ return m_segmentLength;
+}
+
+void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition)
+{
m_dataPosition = dataPosition;
+ m_segmentLength = m_data->getSomeData(m_segment, dataPosition);
ASSERT(m_segmentLength);
- return m_segmentLength;
}
} // namespace blink
« no previous file with comments | « Source/platform/image-decoders/FastSharedBufferReader.h ('k') | Source/platform/image-decoders/FastSharedBufferReaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698