From 04a70543eaa1facf1a54e61caf308bd3fa58740f Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Fri, 9 Aug 2024 21:45:58 -0700 Subject: [PATCH] Trim trailing zeros from build information. [ Cherry-pick of http://go/wvgerrit/212250 ] Certain OEMCrypto implementations are returning build info with trailing C-string null bytes; others are returning all null bytes. This change attempts to trim any trailing zeros. For build info with a single trailing zero, this should fix the format; for those containing all zeros, this will indicate a failure on OEMCrypto's part for returning all zeros. The CDM will not prevent request generation, but will omit the result in the ClientIdentification. The server will decide whether to provide a response or not. Bug: 348497732 Bug: 348498112 Bug: 366819137 Change-Id: I281ab14e0e46116825321a7965d971b9d68c49fc (cherry picked from commit 7c81f7bed4fec8199f7fbdb5e95452eacdf3b3c7) --- libwvdrmengine/cdm/core/src/crypto_session.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 939af6dd..379194e5 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -2541,6 +2541,17 @@ bool CryptoSession::GetBuildInformation(RequestedSecurityLevel security_level, return false; } info->resize(info_length); + // Some OEMCrypto implementations may include trailing null + // bytes in the output. Trim them here. + while (!info->empty() && info->back() == '\0') { + info->pop_back(); + } + if (info->empty()) { + LOGE("BuildInformation() returned corrupted data: length = %zu", + info_length); + return false; + } + return true; }