summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-02-24 15:31:12 -0800
committerChromium commit bot <commit-bot@chromium.org>2017-02-27 18:57:39 +0000
commitc5a1472ec5a809ff524c8888ac5884498801d06f (patch)
tree0097a8358dd5954fb48f4b2a48ea921a22a300ca /fxjs
parent73c9f3bb3d82563d6d4496c4b0204d5c0825e8a2 (diff)
downloadpdfium-c5a1472ec5a809ff524c8888ac5884498801d06f.tar.xz
Fix uninitialized memory read in CJS_Object::GetEmbedObject()
The expected way to create native PDFium objects for JS is via the NewFxDynamicObject() call in C++, but that doesn't mean that the corresponding constructors won't be called from JS. In that case, the internal fields will be uninitialized, and subsequent method calls may try to use them. Add a constructor callback for all PDFium objects that nulls out these fields (shame that v8 doesn't do this by default, but probably saves some cycles). Then ensure that we check for this possibility in all the places it might turn up. Conversely, if we've just gotten a successful return from NewFxDynamicObject(), we know the CJS_Object/EmbedObj are good, so avoid checking there. BUG=695826 Change-Id: Iadad644c4af937def967ddc83daac1dad7544d69 Reviewed-on: https://pdfium-review.googlesource.com/2839 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/fxjs_v8.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 053db07d3b..0c211a130a 100644
--- a/fxjs/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -56,6 +56,12 @@ class CFXJS_ObjDefinition {
v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
fun->InstanceTemplate()->SetInternalFieldCount(2);
+ fun->SetCallHandler([](const v8::FunctionCallbackInfo<v8::Value>& info) {
+ v8::Local<v8::Object> holder = info.Holder();
+ ASSERT(holder->InternalFieldCount() == 2);
+ holder->SetAlignedPointerInInternalField(0, nullptr);
+ holder->SetAlignedPointerInInternalField(1, nullptr);
+ });
if (eObjType == FXJSOBJTYPE_GLOBAL) {
fun->InstanceTemplate()->Set(
v8::Symbol::GetToStringTag(isolate),