From db670e7bcc87e2aba64e451e419fd3a4c047a541 Mon Sep 17 00:00:00 2001 From: John Bruce Date: Wed, 24 May 2023 10:18:38 -0700 Subject: [PATCH] Add tests for ODK overflow functions Merged from http://go/wvgerrit/175855 This includes testing overflow functions that are only used in the Widevine client repository. This patch also includes the following fix for the previous commit: Add type casting for ODK overflow function unit tests Merged from http://go/wvgerrit/175893 The new ODK overflow unit tests are causing some unit test failures in oemcrypto-v18 due to mismatched type comparisons. PiperOrigin-RevId: 535308670 PiperOrigin-RevId: 534890798 Change-Id: I8bb67e47193a92191a91c83bf8a0de61e1b87793 --- .../oemcrypto/odk/include/odk_structs.h | 2 +- .../oemcrypto/odk/test/odk_test.cpp | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libwvdrmengine/oemcrypto/odk/include/odk_structs.h b/libwvdrmengine/oemcrypto/odk/include/odk_structs.h index d0d1a135..ab26f4ec 100644 --- a/libwvdrmengine/oemcrypto/odk/include/odk_structs.h +++ b/libwvdrmengine/oemcrypto/odk/include/odk_structs.h @@ -19,7 +19,7 @@ extern "C" { #define ODK_MINOR_VERSION 2 /* ODK Version string. Date changed automatically on each release. */ -#define ODK_RELEASE_DATE "ODK v18.2 2023-05-05" +#define ODK_RELEASE_DATE "ODK v18.2 2023-05-25" /* The lowest version number for an ODK message. */ #define ODK_FIRST_VERSION 16 diff --git a/libwvdrmengine/oemcrypto/odk/test/odk_test.cpp b/libwvdrmengine/oemcrypto/odk/test/odk_test.cpp index b47946d9..d15fe51d 100644 --- a/libwvdrmengine/oemcrypto/odk/test/odk_test.cpp +++ b/libwvdrmengine/oemcrypto/odk/test/odk_test.cpp @@ -4,6 +4,7 @@ #include "odk.h" +#include #include #include #include @@ -17,6 +18,7 @@ #include "core_message_serialize_proto.h" #include "core_message_types.h" #include "gtest/gtest.h" +#include "odk_overflow.h" #include "odk_structs.h" #include "odk_structs_priv.h" #include "odk_test_helper.h" @@ -1222,6 +1224,37 @@ TEST(OdkTest, CheckReleaseVersion) { << "Version mismatch in odk_structs.h"; } +TEST(OdkOverflowTest, SubtractU64) { + uint64_t result = 0; + EXPECT_FALSE(odk_sub_overflow_u64(10, 5, &result)); + EXPECT_EQ(result, static_cast(10 - 5)); + EXPECT_TRUE(odk_sub_overflow_u64(5, 10, &result)); +} + +TEST(OdkOverflowTest, AddU64) { + uint64_t result = 0; + EXPECT_FALSE(odk_add_overflow_u64(2, 2, &result)); + EXPECT_EQ(result, static_cast(2 + 2)); + EXPECT_TRUE(odk_add_overflow_u64(0xffffffffffffffff, 1, &result)); + EXPECT_TRUE(odk_add_overflow_u64(1, 0xffffffffffffffff, &result)); +} + +TEST(OdkOverflowTest, AddUX) { + size_t result = 0; + EXPECT_FALSE(odk_add_overflow_ux(2, 2, &result)); + EXPECT_EQ(result, static_cast(2 + 2)); + EXPECT_TRUE(odk_add_overflow_ux(SIZE_MAX, 1, &result)); + EXPECT_TRUE(odk_add_overflow_ux(1, SIZE_MAX, &result)); +} + +TEST(OdkOverflowTest, MultiplyUX) { + size_t result = 0; + EXPECT_FALSE(odk_mul_overflow_ux(2, 7, &result)); + EXPECT_EQ(result, static_cast(2 * 7)); + EXPECT_TRUE(odk_mul_overflow_ux(SIZE_MAX >> 1, 4, &result)); + EXPECT_TRUE(odk_mul_overflow_ux(4, SIZE_MAX >> 1, &result)); +} + } // namespace } // namespace wvodk_test