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

Unified Diff: Source/core/html/track/WebVTTParser.cpp

Issue 64303004: Handle buffer boundaries in the WebVTT parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix compilation warning Created 7 years, 1 month 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/core/html/track/WebVTTParser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/track/WebVTTParser.cpp
diff --git a/Source/core/html/track/WebVTTParser.cpp b/Source/core/html/track/WebVTTParser.cpp
index 98de87c2ece687ec98ce5e3a7927be7dccc1d623..b3f0632def09785ca527886cc6e981a44ed51bf9 100644
--- a/Source/core/html/track/WebVTTParser.cpp
+++ b/Source/core/html/track/WebVTTParser.cpp
@@ -135,25 +135,26 @@ void WebVTTParser::getNewRegions(Vector<RefPtr<VTTRegion> >& outputRegions)
void WebVTTParser::parseBytes(const char* data, unsigned length)
{
String textData = m_decoder->decode(data, length);
- parse(textData);
+ m_lineReader.append(textData);
+ parse();
}
void WebVTTParser::flush()
{
String textData = m_decoder->flush();
- parse(textData);
+ m_lineReader.append(textData);
+ m_lineReader.setEndOfStream();
+ parse();
flushPendingCue();
}
-void WebVTTParser::parse(const String& textData)
+void WebVTTParser::parse()
{
// 4.8.10.13.3 WHATWG WebVTT Parser algorithm.
// 1-3 - Initial setup.
- unsigned position = 0;
-
- while (position < textData.length()) {
- String line = collectNextLine(textData, &position);
+ String line;
+ while (m_lineReader.getLine(line)) {
switch (m_state) {
case Initial:
// 4-12 - Check for a valid WebVTT signature.
@@ -215,6 +216,7 @@ void WebVTTParser::parse(const String& textData)
void WebVTTParser::flushPendingCue()
{
+ ASSERT(m_lineReader.isAtEndOfStream());
// If we're in the CueText state when we run out of data, we emit the pending cue.
if (m_state == CueText)
createNewCue();
@@ -564,27 +566,5 @@ void WebVTTParser::skipWhiteSpace(const String& line, unsigned* position)
(*position)++;
}
-void WebVTTParser::skipLineTerminator(const String& data, unsigned* position)
-{
- if (*position >= data.length())
- return;
- if (data[*position] == '\r')
- (*position)++;
- if (*position >= data.length())
- return;
- if (data[*position] == '\n')
- (*position)++;
-}
-
-String WebVTTParser::collectNextLine(const String& data, unsigned* position)
-{
- unsigned oldPosition = *position;
- while (*position < data.length() && data[*position] != '\r' && data[*position] != '\n')
- (*position)++;
- String line = data.substring(oldPosition, *position - oldPosition);
- skipLineTerminator(data, position);
- return line;
-}
-
}
« no previous file with comments | « Source/core/html/track/WebVTTParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698