diff options
author | 2023-12-06 10:57:39 -0800 | |
---|---|---|
committer | 2023-12-07 15:50:13 +0000 | |
commit | e67646edf1a1ad5e7413816490a6ffaa331e7910 (patch) | |
tree | 5504e6fc04f4c380d113d90d6217edcd4e7c6860 | |
parent | c42ed4a081afdc60d54e13e90fd6ea89f5c93c36 (diff) |
input_verifier: check the number of pointers for MOVE events
Before this CL, the check for the existing pointers was not complete:
there was a chance that the MOVE event contained less than the current
number of pointers.
Fix this by checking the number of pointers before comparing the sets of
pointers.
Bug: 312714754
Test: atest libinput_rust_test
Change-Id: I4e6c00aec4247b6cb4c467ac5c2887ee3a90afba
-rw-r--r-- | libs/input/rust/input_verifier.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libs/input/rust/input_verifier.rs b/libs/input/rust/input_verifier.rs index b60d7c971e..867af793bc 100644 --- a/libs/input/rust/input_verifier.rs +++ b/libs/input/rust/input_verifier.rs @@ -272,6 +272,10 @@ impl InputVerifier { return false; }; + if pointers.len() != pointer_properties.len() { + return false; + } + for pointer_property in pointer_properties.iter() { let pointer_id = pointer_property.id; if !pointers.contains(&pointer_id) { @@ -592,4 +596,43 @@ mod tests { ) .is_ok()); } + + // Send a MOVE event with incorrect number of pointers (one of the pointers is missing). + #[test] + fn move_with_wrong_number_of_pointers() { + let mut verifier = InputVerifier::new("Test", /*should_log*/ false); + let pointer_properties = Vec::from([RustPointerProperties { id: 0 }]); + assert!(verifier + .process_movement( + DeviceId(1), + Source::Touchscreen, + input_bindgen::AMOTION_EVENT_ACTION_DOWN, + &pointer_properties, + MotionFlags::empty(), + ) + .is_ok()); + // POINTER 1 DOWN + let two_pointer_properties = + Vec::from([RustPointerProperties { id: 0 }, RustPointerProperties { id: 1 }]); + assert!(verifier + .process_movement( + DeviceId(1), + Source::Touchscreen, + input_bindgen::AMOTION_EVENT_ACTION_POINTER_DOWN + | (1 << input_bindgen::AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + &two_pointer_properties, + MotionFlags::empty(), + ) + .is_ok()); + // MOVE event with 1 pointer missing (the pointer with id = 1). It should be rejected + assert!(verifier + .process_movement( + DeviceId(1), + Source::Touchscreen, + input_bindgen::AMOTION_EVENT_ACTION_MOVE, + &pointer_properties, + MotionFlags::empty(), + ) + .is_err()); + } } |