fix(drm): handle non-UTF-8 output from shaka-packager stderr

Shaka-packager can emit non-UTF-8 bytes in its log output, causing UnicodeDecodeError when reading stderr in text mode. Use explicit errors="replace" encoding. Also harden try_ensure_utf8 fallback paths to always return valid UTF-8 instead of raw bytes.
This commit is contained in:
imSp4rky
2026-04-12 22:19:44 +00:00
parent 8bdb942234
commit 2e7fc1720d
2 changed files with 7 additions and 5 deletions

View File

@@ -421,7 +421,9 @@ class PlayReady:
[binaries.ShakaPackager, *arguments],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
encoding="utf-8",
errors="replace",
)
stream_skipped = False

View File

@@ -516,10 +516,10 @@ def try_ensure_utf8(data: bytes) -> bytes:
# last ditch effort to detect encoding
detection_result = chardet.detect(data)
if not detection_result["encoding"]:
return data
return data.decode(detection_result["encoding"]).encode("utf8")
except UnicodeDecodeError:
return data
return data.decode("utf-8", errors="replace").encode("utf-8")
return data.decode(detection_result["encoding"], errors="replace").encode("utf8")
except (UnicodeDecodeError, LookupError):
return data.decode("utf-8", errors="replace").encode("utf-8")
def get_free_port() -> int: