Skip to content

Truly independent web browser

Compositor: Refuse scrolling state it cannot calculate scrolls with

Aliaksandr Kalenik51d39d0f8192
diff --git a/Libraries/LibCompositing/Rust/src/scrolling/async_scrolling_state.rs b/Libraries/LibCompositing/Rust/src/scrolling/async_scrolling_state.rs
index feaeaf0ba0e..0a3a8d63f29 100644
--- a/Libraries/LibCompositing/Rust/src/scrolling/async_scrolling_state.rs
+++ b/Libraries/LibCompositing/Rust/src/scrolling/async_scrolling_state.rs
@@ -181,6 +181,26 @@ impl Default for AsyncScrollingState {
}
}
+impl AsyncScrollingState {
+ // Scroll offsets and the durations of scroll animations are calculated from these, and a number that is not finite,
+ // or a scale that is not positive, leaves them with no value.
+ pub fn has_only_numbers_scrolls_can_be_calculated_with(&self) -> bool {
+ let is_finite = |point: FloatPoint| point.x.is_finite() && point.y.is_finite();
+ self.device_pixels_per_css_pixel.is_finite()
+ && self.device_pixels_per_css_pixel > 0.0
+ && self
+ .scroll_nodes
+ .iter()
+ .all(|node| is_finite(node.min_scroll_offset) && is_finite(node.max_scroll_offset))
+ && self.scrollbars.iter().all(|scrollbar| {
+ scrollbar.scroll_size.is_finite()
+ && scrollbar.expanded_scroll_size.is_finite()
+ && scrollbar.min_scroll_offset.is_finite()
+ && scrollbar.max_scroll_offset.is_finite()
+ })
+ }
+}
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WheelRoutingAdmission {
Accepted,
diff --git a/Libraries/LibCompositing/Rust/src/scrolling/scroll_state_snapshot.rs b/Libraries/LibCompositing/Rust/src/scrolling/scroll_state_snapshot.rs
index 58400ee5a04..60be8298e72 100644
--- a/Libraries/LibCompositing/Rust/src/scrolling/scroll_state_snapshot.rs
+++ b/Libraries/LibCompositing/Rust/src/scrolling/scroll_state_snapshot.rs
@@ -88,6 +88,11 @@ impl ScrollStateSnapshot {
self.world_transforms_cache.get_or_build(tree, &self.device_offsets)
}
+ pub fn has_only_finite_offsets(&self) -> bool {
+ let is_finite = |offset: &FloatPoint| offset.x.is_finite() && offset.y.is_finite();
+ self.device_offsets.iter().all(is_finite) && self.staged_offsets.iter().all(|staged| is_finite(&staged.offset))
+ }
+
pub fn device_offset_for_index(&self, index: SpatialNodeIndex) -> FloatPoint {
self.device_offsets.get(index.0 as usize).copied().unwrap_or_default()
}
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index c7c327017a3..d75bd0d5775 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -299,7 +299,7 @@ void ConnectionFromWebContent::update_display_list(Web::CompositorContextId cont
if (!context_is_owned_by_this_connection(context_id))
return;
if (!m_compositor_state->update_display_list(context_id, display_list.release_value(), async_scrolling_metadata, move(visual_context_tree), move(resource_transaction), scroll_state_snapshot)) {
- did_misbehave("WebContent published a display list with scrolling state that does not decode");
+ did_misbehave("WebContent published a display list with scrolling state the compositor cannot use");
return;
}
if (display_list_timing_enabled())
diff --git a/Services/Compositor/Rust/src/context_state/mod.rs b/Services/Compositor/Rust/src/context_state/mod.rs
index 334c1a360db..9895018131b 100644
--- a/Services/Compositor/Rust/src/context_state/mod.rs
+++ b/Services/Compositor/Rust/src/context_state/mod.rs
@@ -715,17 +715,24 @@ impl ContextState {
self.parent_context_id = parent_context_id;
}
+ // Returns false, leaving everything as it was, for scrolling state with numbers no scroll can be calculated with.
pub fn install_display_list_update(
&mut self,
display_list: Rc<DisplayList>,
visual_context_tree: AccumulatedVisualContextTree,
scroll_state_snapshot: ScrollStateSnapshot,
now: MonotonicTime,
- ) {
+ ) -> bool {
assert_eq!(
display_list.compatible_visual_context_tree_structural_epoch(),
visual_context_tree.structural_epoch()
);
+ let async_scrolling_state = async_scrolling_state_from_display_list(&display_list);
+ if !scroll_state_snapshot.has_only_finite_offsets()
+ || !async_scrolling_state.has_only_numbers_scrolls_can_be_calculated_with()
+ {
+ return false;
+ }
let scroll_offsets_of_known_nodes = self.scroll_offsets_by_stable_id();
self.scene.install(display_list, visual_context_tree, now);
self.keyboard_scroll_controller.forget_target();
@@ -734,8 +741,6 @@ impl ContextState {
.set_node_count(self.scene.visual_context_tree().as_ref().unwrap().spatial_node_count());
let display_list = self.scene.display_list().as_ref().unwrap().clone();
self.restart_caret_blink_for(&display_list, now);
- let async_scrolling_state =
- async_scrolling_state_from_display_list(self.scene.display_list().as_ref().unwrap());
let mut async_scrolling_viewport_rect = async_scrolling_state.viewport_rect;
self.wheel_gesture_routing
.did_install_scrolling_state(&async_scrolling_state);
@@ -772,6 +777,7 @@ impl ContextState {
if let Some(metadata) = self.scene.display_list().as_ref().unwrap().async_scrolling_metadata() {
self.adopt_keyboard_scroll_state(metadata.keyboard_scroll_state.clone());
}
+ true
}
// Repaints the blinking caret of a display list each time its blink cycle turns it on or off.
diff --git a/Services/Compositor/Rust/src/core/messages.rs b/Services/Compositor/Rust/src/core/messages.rs
index 763ee011cc7..f862df1ba05 100644
--- a/Services/Compositor/Rust/src/core/messages.rs
+++ b/Services/Compositor/Rust/src/core/messages.rs
@@ -185,6 +185,9 @@ impl MessagesFromWebContent<'_> {
impl compositor_web_content_server::Stub for MessagesFromWebContent<'_> {
fn update_scroll_state(&mut self, message: UpdateScrollState) -> Result<(), Misbehavior> {
+ if !message.scroll_state_snapshot.has_only_finite_offsets() {
+ return Err(Misbehavior("Invalid scroll state"));
+ }
if self.context_is_owned_by_sender(message.context_id)? {
self.core.update_scroll_state(
message.context_id,
diff --git a/Services/Compositor/Rust/src/core/mod.rs b/Services/Compositor/Rust/src/core/mod.rs
index b26aacf5c94..4c9b51bbcfe 100644
--- a/Services/Compositor/Rust/src/core/mod.rs
+++ b/Services/Compositor/Rust/src/core/mod.rs
@@ -211,6 +211,7 @@ impl CompositorCore {
context.borrow_mut().set_scroll_capabilities(capabilities);
}
+ // Returns false, leaving everything as it was, for scrolling state with numbers no scroll can be calculated with.
pub fn install_display_list_update(
&self,
context_id: CompositorContextId,
@@ -218,13 +219,13 @@ impl CompositorCore {
visual_context_tree: AccumulatedVisualContextTree,
scroll_state_snapshot: ScrollStateSnapshot,
now: MonotonicTime,
- ) {
+ ) -> bool {
let _entered = self.enter();
let context = self.context_if_present(context_id).expect("context exists");
context
.borrow_mut()
- .install_display_list_update(display_list, visual_context_tree, scroll_state_snapshot, now);
+ .install_display_list_update(display_list, visual_context_tree, scroll_state_snapshot, now)
}
// Returns false, leaving everything as it was, for a tree that does not fit the installed display list.
diff --git a/Services/Compositor/Rust/src/ffi.rs b/Services/Compositor/Rust/src/ffi.rs
index 482dd048add..ef0ab831246 100644
--- a/Services/Compositor/Rust/src/ffi.rs
+++ b/Services/Compositor/Rust/src/ffi.rs
@@ -180,7 +180,8 @@ pub extern "C" fn compositor_core_set_scroll_capabilities(
);
}
-/// Answers false, changing nothing, for async scrolling metadata or a scroll state that do not decode.
+/// Answers false, changing nothing, for async scrolling metadata or a scroll state that do not decode, or that hold
+/// numbers no scroll can be calculated with.
///
/// # Safety
///
@@ -209,8 +210,7 @@ pub unsafe extern "C" fn compositor_core_install_display_list_update(
unsafe { tree_sharing_handle(visual_context_tree) },
scroll_state_snapshot,
MonotonicTime::from_nanoseconds(now_nanoseconds),
- );
- true
+ )
}
/// Answers false, leaving everything as it was, for a tree that does not fit the installed display list.