Skip to content

Commit

Permalink
Fix alignment guessing algorithm returning invalid values
Browse files Browse the repository at this point in the history
If the GCD is not a power of 2, that means the files in the archive
are most likely not aligned (since files are always aligned to
2**n byte boundaries).
  • Loading branch information
leoetlino committed Aug 6, 2018
1 parent 4a3345b commit 7e22255
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sarc/sarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def guess_default_alignment(self) -> int:
gcd = next(iter(self._files.values()))[0] + self._doff
for node in self._files.values():
gcd = math.gcd(gcd, node[0] + self._doff)

if gcd == 0 or gcd & (gcd - 1) != 0:
# If the GCD is not a power of 2, the files are mostly likely NOT aligned.
return 4

return gcd

def get_data_offset(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="sarc",
version="1.0.0-1",
version="1.0.1",
author="leoetlino",
author_email="leo@leolam.fr",
description="Nintendo SARC archive reader and writer",
Expand Down

0 comments on commit 7e22255

Please sign in to comment.