Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsafe Heap constructor usage in DOM objects #16500

Merged
merged 1 commit into from May 4, 2017

Conversation

@MortimerGoro
Copy link
Contributor

MortimerGoro commented Apr 17, 2017

See servo/rust-mozjs#343 (comment)

Heap::new() constructor is unsafe. Heap should be set after reflect_dom_object call in order to prevent potential GC crashes.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Apr 17, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/vreyeparameters.rs, components/script/dom/vrframedata.rs, components/script/dom/extendablemessageevent.rs, components/script/dom/vrstageparameters.rs, components/script/dom/messageevent.rs and 1 more
  • @KiChjang: components/script/dom/vreyeparameters.rs, components/script/dom/vrframedata.rs, components/script/dom/extendablemessageevent.rs, components/script/dom/vrstageparameters.rs, components/script/dom/messageevent.rs and 1 more
@highfive
Copy link

highfive commented Apr 17, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
@asajeffrey
Copy link
Member

asajeffrey commented Apr 17, 2017

cc @jdm

Copy link
Member

asajeffrey left a comment

This is making me think we need to design the API to deal with servo/rust-mozjs#343 properly rather than implement lots of point fixes!

origin: origin,
lastEventId: lastEventId,
};
let ev = reflect_dom_object(ev, global, ExtendableMessageEventBinding::Wrap);
let root = reflect_dom_object(ev, global, ExtendableMessageEventBinding::Wrap);

This comment has been minimized.

@asajeffrey

asajeffrey Apr 17, 2017

Member

Not sure the renaming is buying us anything here.

@@ -75,27 +74,27 @@ impl Gamepad {
state: &WebVRGamepadState) -> Root<Gamepad> {
let buttons = GamepadButtonList::new_from_vr(&global, &state.buttons);
let pose = VRPose::new(&global, &state.pose);

let root = reflect_dom_object(box Gamepad::new_inherited(state.gamepad_id,

This comment has been minimized.

@asajeffrey

asajeffrey Apr 17, 2017

Member

Nit: variable name?

let _ = Float64Array::create(cx,
CreateWith::Slice(&state.axes),
axes.handle_mut());
let _ = Float64Array::create(cx, CreateWith::Slice(&state.axes), array.handle_mut());

This comment has been minimized.

@asajeffrey

asajeffrey Apr 17, 2017

Member

Is there a way to have Float64Array::create allocate directly into root.axes rather than into a dummy variable? @jdm?

This comment has been minimized.

@jdm

jdm May 2, 2017

Member

There is Heap::handle_mut, which would avoid the need for a local stack root: http://doc.servo.org/js/jsapi/struct.Heap.html#method.handle_mut

origin: origin,
lastEventId: lastEventId,
};
reflect_dom_object(ev, global, MessageEventBinding::Wrap)
let root = reflect_dom_object(ev, global, MessageEventBinding::Wrap);

This comment has been minimized.

@asajeffrey

asajeffrey Apr 17, 2017

Member

Nit: variable name?

let cx = global.get_cx();
rooted!(in (cx) let mut array = ptr::null_mut());
unsafe {
let _ = Float32Array::create(cx, CreateWith::Slice(&parameters.offset), array.handle_mut());

This comment has been minimized.

fn create_typed_array(cx: *mut JSContext, src: &[f32], dst: &Heap<*mut JSObject>) {
unsafe {
rooted!(in (cx) let mut array = ptr::null_mut());
let _ = Float32Array::create(cx, CreateWith::Slice(src), array.handle_mut());

This comment has been minimized.

unsafe {
let _ = Float32Array::create(cx,
CreateWith::Slice(&parameters.sitting_to_standing_transform),
array.handle_mut());

This comment has been minimized.

@MortimerGoro MortimerGoro force-pushed the MortimerGoro:unsafe_heap branch from cf73647 to d6aa818 Apr 17, 2017
@jdm
Copy link
Member

jdm commented Apr 17, 2017

All I've got so far is removing the constructor that accepts an argument. I have not been able to figure out any meaningful API change that can prevent problems like this.

@asajeffrey
Copy link
Member

asajeffrey commented Apr 17, 2017

Is there anything clever we can do with destination-passing style to avoid moving heap objects? I vaguely remember talking to @pnkfelix about this, in a different context.

@MortimerGoro MortimerGoro force-pushed the MortimerGoro:unsafe_heap branch from d6aa818 to 2edef1a Apr 28, 2017
@MortimerGoro
Copy link
Contributor Author

MortimerGoro commented May 1, 2017

Hi, any news/ideas about fixing the Heap constructor API?

@jdm we were waiting for this response to continue the PR review: Is there a way to have Float64Array::create allocate directly into root.axes rather than into a dummy variable?

@asajeffrey
Copy link
Member

asajeffrey commented May 2, 2017

Well, the remaining fixes aren't vital, we could land the PR without them. You can fix the build failure (the unit tests need updating) and then r=me. (@jdm speak up if you are unhappy about this!)

@jdm
Copy link
Member

jdm commented May 2, 2017

The unit test problems are unrelated to this PR and are being fixed in #16655.

@MortimerGoro MortimerGoro force-pushed the MortimerGoro:unsafe_heap branch from 2edef1a to efb59b7 May 3, 2017
@MortimerGoro
Copy link
Contributor Author

MortimerGoro commented May 3, 2017

@asajeffrey PR updated allocating directly into heap rather than into a dummy variable, using the heap.handle_mut() method that @jdm recommended

@asajeffrey
Copy link
Member

asajeffrey commented May 4, 2017

OK, at this point @bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented May 4, 2017

📌 Commit efb59b7 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented May 4, 2017

Testing commit efb59b7 with merge e8aa375...

bors-servo added a commit that referenced this pull request May 4, 2017
Fix unsafe Heap constructor usage in DOM objects

<!-- Please describe your changes on the following line: -->

See servo/rust-mozjs#343 (comment)

Heap::new() constructor is unsafe. Heap should be set after reflect_dom_object call in order to prevent potential GC crashes.

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16500)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented May 4, 2017

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev
Approved by: asajeffrey
Pushing e8aa375 to master...

@bors-servo bors-servo merged commit efb59b7 into servo:master May 4, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.