Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e67646ed authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent c42ed4a0
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -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());
    }
}