Protect against race conditions when adding a license

[ Merge of http://go/wvgerrit/142249 and http://go/ag/16307264 ]

This adds concurrency protection to a session when policy
timers are reset to from v15 to v16. The v15 policy timer may still be
in use by the decryption thread.

Bug: 204282907
Bug: 207304220
Test: Unit/Integration tests, GtsMediaTestCases
Change-Id: I4967b3927e47733fb23a1a12b6094d1cd2072918
This commit is contained in:
Rahul Frias
2021-11-19 13:00:11 -08:00
parent a4756e2a7f
commit 84abb87fd8

View File

@@ -387,7 +387,16 @@ CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id,
return EMPTY_KEY_DATA_1;
}
const CdmResponseType sts = session->AddKey(key_data);
CdmResponseType sts = KEY_ADDED;
{
// TODO(rfrias): Refactor. For now lock while adding keys to prevent
// a race condition between this and the decryption thread. This may
// occur if |policy_timers_| is reset when PolicyEngine::SetLicense
// is called.
std::unique_lock<std::recursive_mutex> lock(session_map_lock_);
sts = session->AddKey(key_data);
}
if (sts == KEY_ADDED) {
if (session->is_release()) {
*license_type = kLicenseTypeRelease;