Merge "Add workaround for VERSION_2_2 back compat" into vic-widevine-dev

This commit is contained in:
Treehugger Robot
2025-07-14 14:15:48 -07:00
committed by Android (Google) Code Review

View File

@@ -8,6 +8,8 @@
#include "odk_serialize.h" #include "odk_serialize.h"
#include "odk_message.h"
#include "odk_overflow.h"
#include "odk_structs_priv.h" #include "odk_structs_priv.h"
#include "serialization_base.h" #include "serialization_base.h"
@@ -237,6 +239,36 @@ static void Unpack_OEMCrypto_KeyObject(ODK_Message* msg,
Unpack_OEMCrypto_Substring(msg, &obj->key_data); Unpack_OEMCrypto_Substring(msg, &obj->key_data);
Unpack_OEMCrypto_Substring(msg, &obj->key_control_iv); Unpack_OEMCrypto_Substring(msg, &obj->key_control_iv);
Unpack_OEMCrypto_Substring(msg, &obj->key_control); Unpack_OEMCrypto_Substring(msg, &obj->key_control);
/*
Edge case for servers that incorrectly process protocol VERSION_2_2 padding.
Key data in proto is present, but each key's position in the core
message is missing.
Use the key_data_iv offset to determine if the key_data is present.
This assumes that the serialized protobuf is deterministically ordered, and
that the content key is always 16 bytes. These assumptions should hold true
for v16 and older servers.
*/
if (ODK_Message_GetStatus(msg) == MESSAGE_STATUS_OK &&
obj->key_data.offset == 0 && obj->key_data.length == 0) {
const size_t kKeyDataProtoHeaderSize = 2;
obj->key_data.offset = obj->key_data_iv.offset + obj->key_data_iv.length +
kKeyDataProtoHeaderSize;
obj->key_data.length = 16u; // assume 16-byte key
// Check for overflow. The offset is relative to the end of the core
// message, so add that length to the calculation.
size_t substring_end = 0; // offset + length
size_t end = 0; // offset + length + message_length
if (odk_add_overflow_ux(obj->key_data.offset, obj->key_data.length,
&substring_end) ||
odk_add_overflow_ux(substring_end, ODK_Message_GetSize(msg), &end) ||
end > ODK_Message_GetCapacity(msg)) {
ODK_Message_SetStatus(msg, MESSAGE_STATUS_OVERFLOW_ERROR);
return;
}
}
} }
static void Unpack_ODK_TimerLimits(ODK_Message* msg, ODK_TimerLimits* obj) { static void Unpack_ODK_TimerLimits(ODK_Message* msg, ODK_TimerLimits* obj) {