Bug 1606568 - Prevent excessive instantiation of BigInt parsing template. r=jwalden
☠☠ backed out by 5f9a6b8dc5f2 ☠ ☠
authorPhilip Chimento <philip.chimento@gmail.com>
Mon, 20 Jul 2020 23:58:30 +0000
changeset 541382 7890c93298eced0be0a3b6ba39e21010ec8901d3
parent 541381 cd5b31b3b27ceac4815595b6b48e286b2c56a594
child 541383 a8dac56d2df2c603db3e05f1988988bb84067a0f
push id122207
push userbtara@mozilla.com
push dateTue, 21 Jul 2020 01:05:08 +0000
treeherderautoland@7890c93298ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1606568
milestone80.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 1606568 - Prevent excessive instantiation of BigInt parsing template. r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D82479
js/src/vm/BigIntType.cpp
--- a/js/src/vm/BigIntType.cpp
+++ b/js/src/vm/BigIntType.cpp
@@ -87,16 +87,17 @@
 #include "mozilla/Range.h"
 #include "mozilla/RangedPtr.h"
 #include "mozilla/WrappingOperations.h"
 
 #include <functional>
 #include <limits>
 #include <math.h>
 #include <memory>
+#include <type_traits>  // std::is_same_v
 
 #include "jsapi.h"
 #include "jsnum.h"
 
 #include "builtin/BigInt.h"
 #include "gc/Allocator.h"
 #include "js/Conversions.h"
 #include "js/Initialization.h"
@@ -1549,16 +1550,21 @@ bool BigInt::calculateMaximumDigitsRequi
   return true;
 }
 
 template <typename CharT>
 BigInt* BigInt::parseLiteralDigits(JSContext* cx,
                                    const Range<const CharT> chars,
                                    unsigned radix, bool isNegative,
                                    bool* haveParseError, gc::InitialHeap heap) {
+  static_assert(
+      std::is_same_v<CharT, JS::Latin1Char> || std::is_same_v<CharT, char16_t>,
+      "only the bare minimum character types are supported, to avoid "
+      "excessively instantiating this template");
+
   MOZ_ASSERT(chars.length());
 
   RangedPtr<const CharT> start = chars.begin();
   RangedPtr<const CharT> end = chars.end();
 
   // Skipping leading zeroes.
   while (start[0] == '0') {
     start++;