Bug 1606568 - Prevent excessive instantiation of BigInt parsing template. r=jwalden
authorPhilip Chimento <philip.chimento@gmail.com>
Wed, 22 Jul 2020 02:54:05 +0000
changeset 541559 18a0675bd755d8bad9a5825e43f94294f4375da9
parent 541558 eefb0b6651d78a77e2988424819516e6594a9fa8
child 541560 5bbe7e5166e7ff7eb9f7594d942d8d6b6eb691c9
push id122335
push usercsabou@mozilla.com
push dateWed, 22 Jul 2020 03:27:04 +0000
treeherderautoland@5bbe7e5166e7 [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++;