From f3032a7142d6a0ddf827921bd6fd466a0c7ac0eb Mon Sep 17 00:00:00 2001 From: deeplow Date: Mon, 15 Jan 2024 11:32:30 +0000 Subject: [PATCH] Make big endian explicit in int to bytes Fix issues in older distros that don't yet support python 3.11 where endianness was not a default argument [1]. This is in response to CI failures [2]. [1]: https://docs.python.org/3/library/stdtypes.html#int.to_bytes [2]: https://app.circleci.com/pipelines/github/freedomofpress/dangerzone/2186/workflows/e340ca21-85ce-42b6-9bc3-09e66f96684a/jobs/27380y --- dangerzone/conversion/common.py | 2 +- dangerzone/isolation_provider/base.py | 2 +- dangerzone/isolation_provider/qubes.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dangerzone/conversion/common.py b/dangerzone/conversion/common.py index 6a07f34..f3649c9 100644 --- a/dangerzone/conversion/common.py +++ b/dangerzone/conversion/common.py @@ -76,7 +76,7 @@ class DangerzoneConverter: @classmethod def _write_int(cls, num: int, file: TextIO = sys.stdout) -> None: - cls._write_bytes(num.to_bytes(2, signed=False), file=file) + cls._write_bytes(num.to_bytes(2, "big", signed=False), file=file) # ==== ASYNC METHODS ==== # We run sync methods in async wrappers, because pure async methods are more difficult: diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index f46b7f4..23c2c84 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -36,7 +36,7 @@ def read_int(f: IO[bytes], timeout: float) -> int: untrusted_int = read_bytes(f, 2, timeout) if len(untrusted_int) != 2: raise errors.InterruptedConversionException() - return int.from_bytes(untrusted_int, signed=False) + return int.from_bytes(untrusted_int, "big", signed=False) def read_debug_text(f: IO[bytes], size: int) -> str: diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 98a203e..adbd916 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -97,7 +97,7 @@ class Qubes(IsolationProvider): # 1. The size of the Python zipfile, so that the server can know when to # stop. # 2. The Python zipfile itself. - bufsize_bytes = len(temp_file.getvalue()).to_bytes(4) + bufsize_bytes = len(temp_file.getvalue()).to_bytes(4, "big") wpipe.write(bufsize_bytes) wpipe.write(temp_file.getvalue())