Closed Bug 2051957 Opened 4 months ago Closed 4 months ago

Clean up redundant NaN canonicalizing methods

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox-esr153 --- wontfix
firefox152 --- unaffected
firefox153 --- wontfix
firefox154 --- fixed

People

(Reporter: mccr8, Assigned: jandem)

References

(Blocks 1 open bug)

Details

(Keywords: sec-other, Whiteboard: [adv-main154-])

Attachments

(6 external files)

When passing floating point values from C++ to JS, we need to canonicalize any NaN values, to avoid security problems, because non-canonical-NaNs JS values are interpreted as pointers. Currently we have a hodge podge of ways to convert floating point values to JS values, and some are safe and some are not. Bug 2049714 is going to fix this so that all of the ways to do it are safe, except for the variations that are explicitly unsafe.

Once bug 2049714 lands and sticks for long enough that we are confident it won't be backed out, we should go through and eliminate all of the redundant APIs.

Jandem mentioned JS_NumberValue and CanonicalizedDoubleValue.

The patches that block bug 2049714 also introduce some gross changes we could revert, like going from v.setNumber(x) to v.set(JS_NumberValue(x)). A simple search and replace won't quite work as in at least one place it ended up getting split across multiple lines.

To spell it out a bit more, these two functions can be inlined like so:
CanonicalizedDoubleValue(d) --> DoubleValue(d)
JS_NumberValue(d) --> JS::NumberValue(d)

Part 3 does some cleanups like v.set(NumberValue(JS::CanonicalizeNaN(d)) --> v.set(NumberValue(d)) but I don't see any calls to CanonicalizeNaN outside of the JS engine.

Assignee: nobody → jdemooij
Status: NEW → ASSIGNED
Flags: needinfo?(jdemooij)

Arguable we could also change .set(JS_NumberValue(x)) to .setNumber(x) but I think it would be fair to call that out of scope for this issue and do that separately if we want to. I think that should be completely equivalent? But maybe it would be nice to do it while you are changing the JS_NumberValue calls anyways.

(In reply to Andrew McCreight [:mccr8] from comment #2)

Arguable we could also change .set(JS_NumberValue(x)) to .setNumber(x) but I think it would be fair to call that out of scope for this issue and do that separately if we want to. I think that should be completely equivalent? But maybe it would be nice to do it while you are changing the JS_NumberValue calls anyways.

Yeah it's equivalent. I'll make that change when I get to this :)

Blocks: sm-api
Severity: -- → N/A
Priority: -- → P3
Attached file (secure) —

These are equivalent now that setNumber also canonicalizes NaNs by default (bug 2049714).

Attached file (secure) —

In nsJSContext::AddSupportsPrimitiveTojsvals in nsJSEnvironment.cpp, use
aArgv->setNumber to match the other aArgv->set* calls there.

In Codegen.py this fixes two stale references to TI. This is for generating the
JSJitInfo data used by the JIT.

Attached file (secure) —
Attached file (secure) —

JS::DoubleValue is in NamespaceImports.h so some files now use DoubleValue
instead of JS::DoubleValue to match code for other types.

Attached file (secure) —

setDouble now looks more similar to setDoubleAssumeCanonicalNaN.

Flags: needinfo?(jdemooij)
Pushed by jdemooij@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/80dfe993e933 https://hg.mozilla.org/integration/autoland/rev/55736de70495 part 1 - Use value.setNumber(x) instead of value.set(JS_NumberValue(x)). r=mccr8,geckoview-reviewers,dom-storage-reviewers,TravisLong,owlish,asuth https://github.com/mozilla-firefox/firefox/commit/86014e65e6e7 https://hg.mozilla.org/integration/autoland/rev/84888e1477c5 part 2 - Replace remaining JS_NumberValue calls. r=mccr8,geckoview-reviewers,dom-storage-reviewers,TravisLong,owlish,asuth https://github.com/mozilla-firefox/firefox/commit/38c43ae809f2 https://hg.mozilla.org/integration/autoland/rev/04dfb7f96a5a part 3 - Remove the now-unused JS_NumberValue function. r=spidermonkey-reviewers,jonco https://github.com/mozilla-firefox/firefox/commit/30aaddd90f46 https://hg.mozilla.org/integration/autoland/rev/97e8b58b3187 part 4 - Use JS::DoubleValue instead of the redundant JS::CanonicalizedDoubleValue. r=spidermonkey-reviewers,mccr8,jonco https://github.com/mozilla-firefox/firefox/commit/909d0b52f4b6 https://hg.mozilla.org/integration/autoland/rev/28d71385104b part 5 - Inline Value::bitsFromDouble and remove Value::fromDouble. r=spidermonkey-reviewers,jonco
Attached file (secure) —
Whiteboard: [adv-main154-]
QA Whiteboard: [qa-triage-done-c155/b154][sec]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: