Skip to content

Commit

Permalink
BF: force "little" endianness while xor_byte
Browse files Browse the repository at this point in the history
We are using xor_byte for fingerprint computation and need to
also handle bytes of different length.  When working on big-endian
platforms (such as the only one left s390x on debian) our assumptions
of alignment of bytes in such strings fail. For consistency - always
do it "little endian" way
  • Loading branch information
yarikoptic committed Dec 31, 2024
1 parent e7a8b29 commit d982ab4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/fscacher/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import os.path as op
import shutil
import sys
import time
import joblib
from platformdirs import PlatformDirs
Expand Down Expand Up @@ -247,9 +246,11 @@ def to_tuple(self):

def xor_bytes(b1: bytes, b2: bytes) -> bytes:
length = max(len(b1), len(b2))
i1 = int.from_bytes(b1, sys.byteorder)
i2 = int.from_bytes(b2, sys.byteorder)
return (i1 ^ i2).to_bytes(length, sys.byteorder)
# force 'little' byte order to match our assumptions on how to
# treat bytes of different length.
i1 = int.from_bytes(b1, "little")
i2 = int.from_bytes(b2, "little")
return (i1 ^ i2).to_bytes(length, "little")


def elapsed_since(t: float) -> float:
Expand Down
1 change: 0 additions & 1 deletion src/fscacher/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from itertools import zip_longest
import pytest

from ..cache import xor_bytes


Expand Down

0 comments on commit d982ab4

Please sign in to comment.