Skip to content

Commit

Permalink
Fix data corruption when writing multi-byte characters
Browse files Browse the repository at this point in the history
The classic "byte length" vs "number of characters" mixup.
  • Loading branch information
leoetlino committed Sep 27, 2019
1 parent a6ab6c9 commit 315900c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sarc/sarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def get_file_offsets(self) -> typing.List[typing.Tuple[str, int]]:
offsets.append((self._files[h].name, data_offset))
data_offset += len(self._files[h].data)
return offsets

def get_bytes(self):
stream = io.BytesIO()
self.write(stream)
Expand Down Expand Up @@ -388,7 +388,7 @@ def write(self, stream: typing.BinaryIO) -> int:
stream.write(self._u32(data_offset))
data_offset += len(self._files[h].data)
stream.write(self._u32(data_offset))
string_offset += _align_up(len(self._files[h].name) + 1, 4)
string_offset += _align_up(len(self._files[h].name.encode()) + 1, 4)

# File name table
stream.write(b'SFNT')
Expand Down

0 comments on commit 315900c

Please sign in to comment.