From 9327b95ca77935b59f95e506c1d6aa1bc268adff Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Tue, 8 Aug 2023 14:09:02 -0700 Subject: [PATCH] Do not use text mode for dex verify Summary: The output may not be UTF-8. Reviewed By: beicy Differential Revision: D48088405 fbshipit-source-id: af21d3782c3f5b499c6797ee7d9af4f356429f77 --- pyredex/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pyredex/utils.py b/pyredex/utils.py index 2ee233fb00..b2e85b5a69 100644 --- a/pyredex/utils.py +++ b/pyredex/utils.py @@ -502,14 +502,17 @@ def _verify_dex(dex_file: str, cmd: str) -> bool: logging.debug("Verifying %s...", dex_file) res = subprocess.run( - f"{cmd} '{dex_file}'", shell=True, text=True, capture_output=True + f"{cmd} '{dex_file}'", shell=True, text=False, capture_output=True ) if res.returncode == 0: return True - logging.error( - "Failed verification for %s:\n%s\n---\n%s", dex_file, res.stdout, res.stderr - ) + try: + stderr_str = res.stderr.decode("utf-8") + except BaseException: + stderr_str = "" + + logging.error("Failed verification for %s:\n%s", dex_file, stderr_str) return False