From 116ed6e275a25ba9cfa3d29f2ac8756de8d85242 Mon Sep 17 00:00:00 2001 From: seedds Date: Mon, 1 Jun 2026 23:03:31 +0800 Subject: [PATCH] Use unsigned atom sizes and counts --- src/snowcrypt/snowcrypt.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/snowcrypt/snowcrypt.py b/src/snowcrypt/snowcrypt.py index b131179..923eb5b 100644 --- a/src/snowcrypt/snowcrypt.py +++ b/src/snowcrypt/snowcrypt.py @@ -12,6 +12,7 @@ fshort, fint, flong = (">h", 2), (">i", 4), (">q", 8) +fuint, fulong = (">I", 4), (">Q", 8) class Translator: @@ -31,8 +32,8 @@ def next(self, format: tuple): return data def readAtomSize(self, inStream: BufferedReader) -> int: - atomLength = self.readOne(fint, inStream) - return atomLength if atomLength != 1 else self.readOne(flong, inStream) + atomLength = self.readOne(fuint, inStream) + return atomLength if atomLength != 1 else self.readOne(fulong, inStream) def readOne(self, format: tuple, inStream: BufferedReader): length = format[1] @@ -49,7 +50,7 @@ def write(self, out: BufferedWriter) -> int: def _decrypt_aavd(inStream: BufferedReader, key, iv, t: Translator): # setup - length = t.next(fint) + length = t.next(fuint) aes = newAES(key, MODE_CBC, iv=iv) # for cipher padding, (up to) last 2 bytes are unencrypted @@ -134,8 +135,8 @@ def mdat( t.readOne(fint, inStream) t.readOne(fint, inStream) t.readOne(fint, inStream) - sum_block_length = t.readOne(fint, inStream) - block_count = t.readOne(fint, inStream) + sum_block_length = t.readOne(fuint, inStream) + block_count = t.readOne(fuint, inStream) # next come the atom specific fields # aavd has a list of sample sizes and then the samples.