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

Side by Side 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: Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved. 2 * Copyright (C) 2015 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size _t length, char* buffer) 44 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size _t length, char* buffer)
45 { 45 {
46 RELEASE_ASSERT(dataPosition + length <= m_data->size()); 46 RELEASE_ASSERT(dataPosition + length <= m_data->size());
47 47
48 // Use the cached segment if it can serve the request. 48 // Use the cached segment if it can serve the request.
49 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio n + m_segmentLength) 49 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio n + m_segmentLength)
50 return m_segment + dataPosition - m_dataPosition; 50 return m_segment + dataPosition - m_dataPosition;
51 51
52 // Return a pointer into |m_data| if the request doesn't span segments. 52 // Return a pointer into |m_data| if the request doesn't span segments.
Peter Kasting 2015/03/20 01:10:42 We can simplify the function by replacing everythi
kbalazs 2015/03/20 20:20:42 Quite frankly I don't see how is this simpler. To
Peter Kasting 2015/03/20 20:29:33 Fair enough. "Simpler" in this case means that it
53 m_dataPosition = dataPosition; 53 m_dataPosition = dataPosition;
54 m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition); 54 m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition);
55 ASSERT(m_segmentLength); 55 ASSERT(m_segmentLength);
56 if (length <= m_segmentLength) 56 if (length <= m_segmentLength)
57 return m_segment; 57 return m_segment;
58 58
59 for (char* tempBuffer = buffer; length;) { 59 char* dest = buffer;
Peter Kasting 2015/03/20 20:29:33 Nit: Convert the while to a for so you can move th
60 while (true) {
60 size_t copy = std::min(length, m_segmentLength); 61 size_t copy = std::min(length, m_segmentLength);
61 memcpy(tempBuffer, m_segment, copy); 62 memcpy(dest, m_segment, copy);
62 m_dataPosition += copy; 63 m_dataPosition += copy;
kbalazs 2015/03/25 19:38:10 I also introduced an error. m_dataPosition should
63 length -= copy; 64 length -= copy;
64 tempBuffer += copy; 65 if (!length) {
66 // Done.
67 return buffer;
68 }
65 69
70 // Continue reading the next segment.
71 dest += copy;
66 m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition); 72 m_segmentLength = m_data->getSomeData(m_segment, m_dataPosition);
67 ASSERT(m_segmentLength); 73 ASSERT(m_segmentLength);
68 } 74 }
69 return buffer; 75
76 ASSERT_NOT_REACHED();
Peter Kasting 2015/03/20 01:10:42 I think these two lines will trigger MSVC warning
kbalazs 2015/03/20 20:20:42 Acknowledged.
77 return 0;
70 } 78 }
71 79
72 size_t FastSharedBufferReader::getSomeData(const char*& someData, size_t dataPos ition) 80 size_t FastSharedBufferReader::getSomeData(const char*& someData, size_t dataPos ition)
73 { 81 {
74 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); 82 m_segmentLength = m_data->getSomeData(m_segment, dataPosition);
75 someData = m_segment; 83 someData = m_segment;
76 m_dataPosition = dataPosition; 84 m_dataPosition = dataPosition;
77 ASSERT(m_segmentLength); 85 ASSERT(m_segmentLength);
78 return m_segmentLength; 86 return m_segmentLength;
79 } 87 }
80 88
81 } // namespace blink 89 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698