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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp

Issue 2245003002: [Binding] Load 4 bytes to detect BOM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp
index 512fa575b9ed32ca913e1b38b3b52ddb8a369fc3..98c00fa4eb987ae7df2fc746eb3bc312d6ee8dc0 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptStreamer.cpp
@@ -498,11 +498,15 @@ void ScriptStreamer::notifyAppendData(ScriptResource* resource)
// here, because it might contain incomplete UTF-8 characters. Also note
// that have at least s_smallScriptThreshold worth of data, which is more
// than enough for detecting a BOM.
- const char* data = 0;
- size_t length = resource->resourceBuffer()->getSomeData(data, static_cast<size_t>(0));
+ constexpr size_t maximumLengthOfBOM = 4;
+ char maybeBOM[maximumLengthOfBOM] = {};
+ if (!resource->resourceBuffer()->getPartAsBytes(maybeBOM, static_cast<size_t>(0), maximumLengthOfBOM)) {
+ NOTREACHED();
+ return;
+ }
std::unique_ptr<TextResourceDecoder> decoder(TextResourceDecoder::create("application/javascript", resource->encoding()));
- lengthOfBOM = decoder->checkForBOM(data, length);
+ lengthOfBOM = decoder->checkForBOM(maybeBOM, maximumLengthOfBOM);
// Maybe the encoding changed because we saw the BOM; get the encoding
// from the decoder.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698