From cf85ce692041dd8e24602cff0d1ae0107bb3b7d3 Mon Sep 17 00:00:00 2001 From: Pranav Date: Mon, 26 May 2025 13:13:54 +0530 Subject: [PATCH] Fix endianness bug when generating fingerprint in big endian machines Fixes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1093700 --- acoustid.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/acoustid.py b/acoustid.py index c7cb8d8..31be692 100644 --- a/acoustid.py +++ b/acoustid.py @@ -21,6 +21,9 @@ import requests import contextlib import errno +import sys +if sys.byteorder == 'big': + import struct try: import audioread @@ -206,6 +209,17 @@ def _api_request(url, params, timeout=None): except ValueError: raise WebServiceError('response is not valid JSON') +def byteswap(s): + """Swaps the endianness of the bytestring s, which must be an array + of shorts (16-bit signed integers). + """ + assert len(s) % 2 == 0 + parts = [] + for i in range(0, len(s), 2): + chunk = s[i:i + 2] + newchunk = struct.pack('>h', *struct.unpack('= endposition: break