diff options
author | 2023-08-11 17:48:43 +0000 | |
---|---|---|
committer | 2023-08-11 19:33:13 +0000 | |
commit | 3117a44a2bb277a99cf90ffb57086a3f2a5aae8f (patch) | |
tree | 5a3b33467a048440a46dd4b877fb3a5e32a4c972 | |
parent | 1a6e0bcb0c84d26cfdd482d82ef83902a9c9ef00 (diff) |
InputVerifier: Accept invalid utf-8 strings silently
Rust's String seems to have more strict requirements than cpp's
std::string, since its creation will fail if the string is not valid in
its encoding format. rust::String from cxxbridge escalates the error
and causes a panic.
Since we do not perform a validity check on the std::string that comes
from apps, we must use rust::String::lossy() to create the rust::String
for cxxbridge, since it is tolorant of invalid encodings.
Bug: 295014987
Test: atest libinput_tests
Change-Id: I45ecc6117a43cf25ac6ac15fd57ae25e7174d88f
-rw-r--r-- | libs/input/InputVerifier.cpp | 2 | ||||
-rw-r--r-- | libs/input/tests/Android.bp | 1 | ||||
-rw-r--r-- | libs/input/tests/InputVerifier_test.cpp | 29 |
3 files changed, 31 insertions, 1 deletions
diff --git a/libs/input/InputVerifier.cpp b/libs/input/InputVerifier.cpp index 32b4ca0fc1..9745e89234 100644 --- a/libs/input/InputVerifier.cpp +++ b/libs/input/InputVerifier.cpp @@ -29,7 +29,7 @@ namespace android { // --- InputVerifier --- InputVerifier::InputVerifier(const std::string& name) - : mVerifier(android::input::verifier::create(name)){}; + : mVerifier(android::input::verifier::create(rust::String::lossy(name))){}; Result<void> InputVerifier::processMovement(int32_t deviceId, int32_t action, uint32_t pointerCount, const PointerProperties* pointerProperties, diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp index cadac88030..86b996b3b6 100644 --- a/libs/input/tests/Android.bp +++ b/libs/input/tests/Android.bp @@ -18,6 +18,7 @@ cc_test { "InputDevice_test.cpp", "InputEvent_test.cpp", "InputPublisherAndConsumer_test.cpp", + "InputVerifier_test.cpp", "MotionPredictor_test.cpp", "RingBuffer_test.cpp", "TfLiteMotionPredictor_test.cpp", diff --git a/libs/input/tests/InputVerifier_test.cpp b/libs/input/tests/InputVerifier_test.cpp new file mode 100644 index 0000000000..e24fa6ed0b --- /dev/null +++ b/libs/input/tests/InputVerifier_test.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <gtest/gtest.h> +#include <input/InputVerifier.h> +#include <string> + +namespace android { + +TEST(InputVerifierTest, CreationWithInvalidUtfStringDoesNotCrash) { + constexpr char bytes[] = {static_cast<char>(0xC0), static_cast<char>(0x80)}; + const std::string name(bytes, sizeof(bytes)); + InputVerifier verifier(name); +} + +} // namespace android |