Support duplicated SignedMessages in Cdm.set_service_certificate

Fixes #41

Seems some services like TF1 (France) returns a SignedMessage twice in one response body by mistake, resulting in a partial parse decoding error as pywidevine doesn't expect the parsed-then-serialized data to differ from the received data.

This workaround checks if the parsed-then-serialized data is in the received data multiple times without any leftover data. If there's no leftover data it considers it safe to continue.
This commit is contained in:
rlaphoenix 2023-12-06 15:36:27 +00:00
parent 17cefbf1d8
commit a04e751aa1
1 changed files with 8 additions and 1 deletions

View File

@ -222,7 +222,14 @@ class Cdm:
try: try:
signed_message.ParseFromString(certificate) signed_message.ParseFromString(certificate)
if signed_message.SerializeToString() == certificate: if (
signed_message.SerializeToString() == certificate or
# See https://github.com/devine-dl/pywidevine/issues/41
all(
bytes(chunk) == signed_message.SerializeToString()
for chunk in zip(*[iter(certificate)] * len(signed_message.SerializeToString()))
)
):
signed_drm_certificate.ParseFromString(signed_message.msg) signed_drm_certificate.ParseFromString(signed_message.msg)
else: else:
signed_drm_certificate.ParseFromString(certificate) signed_drm_certificate.ParseFromString(certificate)