summaryrefslogtreecommitdiff
path: root/audio/common/all-versions/default/tests/hidlutils_tests.cpp
diff options
context:
space:
mode:
authorjiabin <jiabin@google.com>2022-07-11 23:28:48 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-07-11 23:28:48 +0000
commitc9c8e96cfde05bc2fb44a5221d5169c155d0bd95 (patch)
tree888d2e03164b74a4b2066c5b7141925551472029 /audio/common/all-versions/default/tests/hidlutils_tests.cpp
parent5b71f85740a99e53854276a222f194c9e6c4e204 (diff)
parent3074154353d66c91e2cb87d24368f8365f300f9c (diff)
[automerge] Fix array out of bound in audioTransportToHal. 2p: f16c6d3a57 2p: 0d43585645 am: 3074154353
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/19214732 Change-Id: I816384174e4a35d262f5406bf5100a54d3f6e976 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'audio/common/all-versions/default/tests/hidlutils_tests.cpp')
-rw-r--r--audio/common/all-versions/default/tests/hidlutils_tests.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/audio/common/all-versions/default/tests/hidlutils_tests.cpp b/audio/common/all-versions/default/tests/hidlutils_tests.cpp
index ec16b0252f..e6e22807a9 100644
--- a/audio/common/all-versions/default/tests/hidlutils_tests.cpp
+++ b/audio/common/all-versions/default/tests/hidlutils_tests.cpp
@@ -954,6 +954,18 @@ TEST(HidlUtils, ConvertAudioPortConfig) {
EXPECT_TRUE(audio_port_configs_are_equal(&halConfig, &halConfigBack));
}
+static AudioProfile generateValidAudioProfile() {
+ AudioProfile profile;
+ profile.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT);
+ profile.sampleRates.resize(2);
+ profile.sampleRates[0] = 44100;
+ profile.sampleRates[1] = 48000;
+ profile.channelMasks.resize(2);
+ profile.channelMasks[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO);
+ profile.channelMasks[1] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO);
+ return profile;
+}
+
TEST(HidlUtils, ConvertInvalidAudioTransports) {
hidl_vec<AudioTransport> invalid;
struct audio_port_v7 halInvalid = {};
@@ -973,20 +985,32 @@ TEST(HidlUtils, ConvertInvalidAudioTransports) {
invalid[0].audioCapability.edid(hidl_vec<uint8_t>(EXTRA_AUDIO_DESCRIPTOR_SIZE + 1));
invalid[1].encapsulationType = "random string";
EXPECT_EQ(BAD_VALUE, HidlUtils::audioTransportsToHal(invalid, &halInvalid));
+
+ // The size of audio profile must not be greater than the maximum value.
+ invalid.resize(0);
+ invalid.resize(AUDIO_PORT_MAX_AUDIO_PROFILES + 1);
+ for (size_t i = 0; i < invalid.size(); ++i) {
+ invalid[i].audioCapability.profile(generateValidAudioProfile());
+ invalid[i].encapsulationType =
+ toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_NONE);
+ }
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioTransportsToHal(invalid, &halInvalid));
+
+ // The size of extra audio descriptors must not be greater than the maximum value.
+ invalid.resize(0);
+ invalid.resize(AUDIO_PORT_MAX_EXTRA_AUDIO_DESCRIPTORS + 1);
+ for (size_t i = 0; i < invalid.size(); ++i) {
+ invalid[i].audioCapability.edid({0x11, 0x06, 0x01});
+ invalid[i].encapsulationType =
+ toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_IEC61937);
+ }
+ EXPECT_EQ(BAD_VALUE, HidlUtils::audioTransportsToHal(invalid, &halInvalid));
}
TEST(HidlUtils, ConvertAudioTransports) {
hidl_vec<AudioTransport> transports;
transports.resize(2);
- AudioProfile profile;
- profile.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT);
- profile.sampleRates.resize(2);
- profile.sampleRates[0] = 44100;
- profile.sampleRates[1] = 48000;
- profile.channelMasks.resize(2);
- profile.channelMasks[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_MONO);
- profile.channelMasks[1] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO);
- transports[0].audioCapability.profile(profile);
+ transports[0].audioCapability.profile(generateValidAudioProfile());
hidl_vec<uint8_t> shortAudioDescriptor({0x11, 0x06, 0x01});
transports[0].encapsulationType =
toString(xsd::AudioEncapsulationType::AUDIO_ENCAPSULATION_TYPE_NONE);