From 315900c92cbe297c7536e059db9db720fe808232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 27 Sep 2019 19:03:27 +0200 Subject: [PATCH] Fix data corruption when writing multi-byte characters The classic "byte length" vs "number of characters" mixup. --- sarc/sarc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sarc/sarc.py b/sarc/sarc.py index 759cf14..8f194f9 100644 --- a/sarc/sarc.py +++ b/sarc/sarc.py @@ -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) @@ -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')