From a04e751aa1fe62d67728cada8e4091dbfc308b30 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 6 Dec 2023 15:36:27 +0000 Subject: [PATCH] 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. --- pywidevine/cdm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index e493ebc..758c459 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -222,7 +222,14 @@ class Cdm: try: 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) else: signed_drm_certificate.ParseFromString(certificate)