Title: [261174] trunk/Source/_javascript_Core
Revision
261174
Author
ysuz...@apple.com
Date
2020-05-05 09:24:01 -0700 (Tue, 05 May 2020)

Log Message

[JSC] JSBigInt::maxLengthBits and JSBigInt::maxLength are wrong
https://bugs.webkit.org/show_bug.cgi?id=211445

Reviewed by Mark Lam.

JSBigInt::maxLengthBits and JSBigInt::maxLength definitions are wrong.

1. We are defining maxLength and maxLengthBits as an unrelated value to each other. This is wrong.
   maxLength should be defined as maxLengthBits / (sizeof(Digit) * bitsPerByte).
2. We use `sizeof(void*)` and assume that `sizeof(Digit) == sizeof(void*)`. This is wrong in ARM64_32 environment
   where Digit size is sizeof(uint64_t) while the pointer size is sizeof(uint32_t). This causes compile errors in ARM64_32
   when the code is using these values with static_assert.

* runtime/JSBigInt.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (261173 => 261174)


--- trunk/Source/_javascript_Core/ChangeLog	2020-05-05 16:09:05 UTC (rev 261173)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-05-05 16:24:01 UTC (rev 261174)
@@ -1,5 +1,22 @@
 2020-05-05  Yusuke Suzuki  <ysuz...@apple.com>
 
+        [JSC] JSBigInt::maxLengthBits and JSBigInt::maxLength are wrong
+        https://bugs.webkit.org/show_bug.cgi?id=211445
+
+        Reviewed by Mark Lam.
+
+        JSBigInt::maxLengthBits and JSBigInt::maxLength definitions are wrong.
+
+        1. We are defining maxLength and maxLengthBits as an unrelated value to each other. This is wrong.
+           maxLength should be defined as maxLengthBits / (sizeof(Digit) * bitsPerByte).
+        2. We use `sizeof(void*)` and assume that `sizeof(Digit) == sizeof(void*)`. This is wrong in ARM64_32 environment
+           where Digit size is sizeof(uint64_t) while the pointer size is sizeof(uint32_t). This causes compile errors in ARM64_32
+           when the code is using these values with static_assert.
+
+        * runtime/JSBigInt.h:
+
+2020-05-05  Yusuke Suzuki  <ysuz...@apple.com>
+
         Unreviewed, reverting r261156.
 
         Break ARM64_32 build due to existing bug

Modified: trunk/Source/_javascript_Core/runtime/JSBigInt.h (261173 => 261174)


--- trunk/Source/_javascript_Core/runtime/JSBigInt.h	2020-05-05 16:09:05 UTC (rev 261173)
+++ trunk/Source/_javascript_Core/runtime/JSBigInt.h	2020-05-05 16:24:01 UTC (rev 261174)
@@ -434,8 +434,9 @@
     // maxInt / digitBits. However, we use a lower limit for now, because
     // raising it later is easier than lowering it.
     // Support up to 1 million bits.
-    static constexpr unsigned maxLength = 1024 * 1024 / (sizeof(void*) * bitsPerByte);
-    static constexpr unsigned maxLengthBits = maxInt - sizeof(void*) * bitsPerByte - 1;
+    static constexpr unsigned maxLengthBits = 1024 * 1024;
+    static constexpr unsigned maxLength = maxLengthBits / digitBits;
+    static_assert(maxLengthBits % digitBits == 0);
     
     static uint64_t calculateMaximumCharactersRequired(unsigned length, unsigned radix, Digit lastDigit, bool sign);
     
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to