mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-05-16 21:59:26 +00:00
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:
@@ -421,7 +421,9 @@ class PlayReady:
|
|||||||
[binaries.ShakaPackager, *arguments],
|
[binaries.ShakaPackager, *arguments],
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
universal_newlines=True,
|
text=True,
|
||||||
|
encoding="utf-8",
|
||||||
|
errors="replace",
|
||||||
)
|
)
|
||||||
|
|
||||||
stream_skipped = False
|
stream_skipped = False
|
||||||
|
|||||||
@@ -516,10 +516,10 @@ def try_ensure_utf8(data: bytes) -> bytes:
|
|||||||
# last ditch effort to detect encoding
|
# last ditch effort to detect encoding
|
||||||
detection_result = chardet.detect(data)
|
detection_result = chardet.detect(data)
|
||||||
if not detection_result["encoding"]:
|
if not detection_result["encoding"]:
|
||||||
return data
|
return data.decode("utf-8", errors="replace").encode("utf-8")
|
||||||
return data.decode(detection_result["encoding"]).encode("utf8")
|
return data.decode(detection_result["encoding"], errors="replace").encode("utf8")
|
||||||
except UnicodeDecodeError:
|
except (UnicodeDecodeError, LookupError):
|
||||||
return data
|
return data.decode("utf-8", errors="replace").encode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def get_free_port() -> int:
|
def get_free_port() -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user