Bug 1497612 - Baldr: add missing oom check for GetOptimizedBuildId (r=lth)
authorLuke Wagner <luke@mozilla.com>
Wed, 10 Oct 2018 14:56:44 -0500
changeset 499090 43a51bc9a77dc2f59196a644798c1911a18615a3
parent 499030 edeba530712124ce1b30693042d4c2296319300f
child 499091 203a8e58e64c86ba7b9cf8b66aec101b10eca3ec
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1497612
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497612 - Baldr: add missing oom check for GetOptimizedBuildId (r=lth)
js/src/jsapi.h
js/src/wasm/WasmModule.cpp
js/src/wasm/WasmModule.h
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3524,17 +3524,17 @@ class OptimizedEncodingListener
     virtual MozExternalRefCountType MOZ_XPCOM_ABI AddRef() = 0;
     virtual MozExternalRefCountType MOZ_XPCOM_ABI Release() = 0;
 
     // SpiderMonkey may optionally call storeOptimizedEncoding() after it has
     // finished processing a streamed resource.
     virtual void storeOptimizedEncoding(const uint8_t* bytes, size_t length) = 0;
 };
 
-extern JS_PUBLIC_API(bool)
+extern MOZ_MUST_USE JS_PUBLIC_API(bool)
 GetOptimizedEncodingBuildId(BuildIdCharVector* buildId);
 
 class JS_PUBLIC_API(StreamConsumer)
 {
   protected:
     // AsyncStreamConsumers are created and destroyed by SpiderMonkey.
     StreamConsumer() = default;
     virtual ~StreamConsumer() = default;
--- a/js/src/wasm/WasmModule.cpp
+++ b/js/src/wasm/WasmModule.cpp
@@ -188,17 +188,22 @@ Module::testingBlockOnTier2Complete() co
         std::this_thread::sleep_for(std::chrono::milliseconds(1));
     }
 }
 
 /* virtual */ size_t
 Module::serializedSize(const LinkData& linkData) const
 {
     JS::BuildIdCharVector buildId;
-    JS::GetOptimizedEncodingBuildId(&buildId);
+    {
+        AutoEnterOOMUnsafeRegion oom;
+        if (!GetOptimizedEncodingBuildId(&buildId)) {
+            oom.crash("getting build id");
+        }
+    }
 
     return SerializedPodVectorSize(buildId) +
            linkData.serializedSize() +
            SerializedVectorSize(imports_) +
            SerializedVectorSize(exports_) +
            SerializedVectorSize(dataSegments_) +
            SerializedVectorSize(elemSegments_) +
            SerializedVectorSize(customSections_) +
@@ -207,17 +212,22 @@ Module::serializedSize(const LinkData& l
 
 /* virtual */ void
 Module::serialize(const LinkData& linkData, uint8_t* begin, size_t size) const
 {
     MOZ_RELEASE_ASSERT(!metadata().debugEnabled);
     MOZ_RELEASE_ASSERT(code_->hasTier(Tier::Serialized));
 
     JS::BuildIdCharVector buildId;
-    JS::GetOptimizedEncodingBuildId(&buildId);
+    {
+        AutoEnterOOMUnsafeRegion oom;
+        if (!GetOptimizedEncodingBuildId(&buildId)) {
+            oom.crash("getting build id");
+        }
+    }
 
     uint8_t* cursor = begin;
     cursor = SerializePodVector(cursor, buildId);
     cursor = linkData.serialize(cursor);
     cursor = SerializeVector(cursor, imports_);
     cursor = SerializeVector(cursor, exports_);
     cursor = SerializeVector(cursor, dataSegments_);
     cursor = SerializeVector(cursor, elemSegments_);
@@ -235,17 +245,19 @@ Module::deserialize(const uint8_t* begin
         if (!metadata) {
             return nullptr;
         }
     }
 
     const uint8_t* cursor = begin;
 
     JS::BuildIdCharVector currentBuildId;
-    JS::GetOptimizedEncodingBuildId(&currentBuildId);
+    if (!GetOptimizedEncodingBuildId(&currentBuildId)) {
+        return nullptr;
+    }
 
     JS::BuildIdCharVector deserializedBuildId;
     cursor = DeserializePodVector(cursor, &deserializedBuildId);
     if (!cursor) {
         return nullptr;
     }
 
     MOZ_RELEASE_ASSERT(EqualContainers(currentBuildId, deserializedBuildId));
--- a/js/src/wasm/WasmModule.h
+++ b/js/src/wasm/WasmModule.h
@@ -190,17 +190,17 @@ class Module : public JS::WasmModule
     bool extractCode(JSContext* cx, Tier tier, MutableHandleValue vp) const;
 };
 
 typedef RefPtr<Module> MutableModule;
 typedef RefPtr<const Module> SharedModule;
 
 // JS API implementations:
 
-bool
+MOZ_MUST_USE bool
 GetOptimizedEncodingBuildId(JS::BuildIdCharVector* buildId);
 
 RefPtr<JS::WasmModule>
 DeserializeModule(PRFileDesc* bytecode, UniqueChars filename, unsigned line);
 
 } // namespace wasm
 } // namespace js