Skip to content

Commit

Permalink
Support duplicated SignedMessages in Cdm.set_service_certificate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rlaphoenix committed Dec 6, 2023
1 parent 17cefbf commit a04e751
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pywidevine/cdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,14 @@ def set_service_certificate(self, session_id: bytes, certificate: Optional[Union

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)
Expand Down

0 comments on commit a04e751

Please sign in to comment.