Title: [203925] trunk/Source/_javascript_Core
- Revision
- 203925
- Author
- [email protected]
- Date
- 2016-07-29 16:42:08 -0700 (Fri, 29 Jul 2016)
Log Message
Undefined Behavior in JSValue cast from NaN
https://bugs.webkit.org/show_bug.cgi?id=160322
Patch by Jonathan Bedard <[email protected]> on 2016-07-29
Reviewed by Mark Lam.
JSValues can be constructed from doubles, and in some cases, are deliberately constructed with NaN values.
In circumstances where NaN is bound through the default JSValue constructor, however, an undefined conversion
to int32_t occurs. While the subsequent if statement should fail and construct the JSValue through the explicit
double constructor, given that the deliberate use of NaN is fairly common, it seems that the jsNaN() function
should immediately call the explicit double constructor both for efficiency and to prevent inadvertent
suppressing of any other bugs which may be instantiating a JSValue with a NaN double.
* runtime/JSCJSValueInlines.h:
(JSC::jsNaN): Explicit double construction for NaN JSValues to avoid undefined behavior.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (203924 => 203925)
--- trunk/Source/_javascript_Core/ChangeLog 2016-07-29 23:41:54 UTC (rev 203924)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-07-29 23:42:08 UTC (rev 203925)
@@ -1,3 +1,21 @@
+2016-07-29 Jonathan Bedard <[email protected]>
+
+ Undefined Behavior in JSValue cast from NaN
+ https://bugs.webkit.org/show_bug.cgi?id=160322
+
+ Reviewed by Mark Lam.
+
+ JSValues can be constructed from doubles, and in some cases, are deliberately constructed with NaN values.
+
+ In circumstances where NaN is bound through the default JSValue constructor, however, an undefined conversion
+ to int32_t occurs. While the subsequent if statement should fail and construct the JSValue through the explicit
+ double constructor, given that the deliberate use of NaN is fairly common, it seems that the jsNaN() function
+ should immediately call the explicit double constructor both for efficiency and to prevent inadvertent
+ suppressing of any other bugs which may be instantiating a JSValue with a NaN double.
+
+ * runtime/JSCJSValueInlines.h:
+ (JSC::jsNaN): Explicit double construction for NaN JSValues to avoid undefined behavior.
+
2016-07-29 Michael Saboff <[email protected]>
Refactor DFG::Node::hasLocal() to accessesStack()
Modified: trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h (203924 => 203925)
--- trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h 2016-07-29 23:41:54 UTC (rev 203924)
+++ trunk/Source/_javascript_Core/runtime/JSCJSValueInlines.h 2016-07-29 23:42:08 UTC (rev 203925)
@@ -70,7 +70,7 @@
inline JSValue jsNaN()
{
- return JSValue(PNaN);
+ return JSValue(JSValue::EncodeAsDouble, PNaN);
}
inline JSValue::JSValue(char i)
@@ -140,6 +140,7 @@
inline JSValue::JSValue(double d)
{
+ // Note: while this behavior is undefined for NaN and inf, the subsequent statement will catch these cases.
const int32_t asInt32 = static_cast<int32_t>(d);
if (asInt32 != d || (!asInt32 && std::signbit(d))) { // true for -0.0
*this = JSValue(EncodeAsDouble, d);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes