@@ -8101,6 +8101,17 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) {
81018101 ASSERT_EQ(keyArgs.scanCode, verifiedKey.scanCode);
81028102 ASSERT_EQ(keyArgs.metaState, verifiedKey.metaState);
81038103 ASSERT_EQ(0, verifiedKey.repeatCount);
8104+
8105+ // InputEvent and subclasses don't have a virtual destructor and only
8106+ // InputEvent's destructor gets called when `verified` goes out of scope,
8107+ // even if `verifyInputEvent` returns an object of a subclass. To fix this,
8108+ // we should either consider using std::variant in some way, or introduce an
8109+ // intermediate POD data structure that we will put the data into just prior
8110+ // to signing. Adding virtual functions to these classes is undesirable as
8111+ // the bytes in these objects are getting signed. As a temporary fix, cast
8112+ // the pointer to the correct class (which is statically known) before
8113+ // destruction.
8114+ delete (VerifiedKeyEvent*)verified.release();
81048115}
81058116
81068117TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
@@ -8148,6 +8159,10 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
81488159 EXPECT_EQ(motionArgs.downTime, verifiedMotion.downTimeNanos);
81498160 EXPECT_EQ(motionArgs.metaState, verifiedMotion.metaState);
81508161 EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
8162+
8163+ // Cast to the correct type before destruction. See explanation at the end
8164+ // of the VerifyInputEvent_KeyEvent test.
8165+ delete (VerifiedMotionEvent*)verified.release();
81518166}
81528167
81538168/**
0 commit comments