From c5a1472ec5a809ff524c8888ac5884498801d06f Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 24 Feb 2017 15:31:12 -0800 Subject: 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 Commit-Queue: Tom Sepez --- fxjs/fxjs_v8.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'fxjs/fxjs_v8.cpp') 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 fun = v8::FunctionTemplate::New(isolate); fun->InstanceTemplate()->SetInternalFieldCount(2); + fun->SetCallHandler([](const v8::FunctionCallbackInfo& info) { + v8::Local 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), -- cgit v1.2.3