/avoid_negative_signed_int.diff Secret
Last active
July 2, 2020 05:23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libec_crcs_original.py b/libec_crcs.py | |
index a80c823..518c737 100644 | |
--- a/libec_crcs_original.py | |
+++ b/libec_crcs.py | |
@@ -13,7 +13,15 @@ libec_crc_alt = getattr(libec, 'liberasurecode_crc32_alt', libec.crc32) | |
def crc_alt(data): | |
- return ctypes.c_uint(libec_crc_alt(0, ctypes.c_char_p(data), len(data))).value | |
+ return ctypes.c_uint(libec_crc_alt(0, ctypes.c_char_p(data), len(data))).value | |
+ | |
+ | |
+def crc_zlib(data): | |
+ zlib_crc = zlib.crc32(data) | |
+ if zlib_crc < 0: | |
+ zlib_crc = zlib_crc & 0xffffffff | |
+ return zlib_crc | |
+ | |
for frag in sys.argv[1:]: | |
with open(frag, 'rb') as fp: | |
@@ -29,6 +37,6 @@ for frag in sys.argv[1:]: | |
).lstrip().format( | |
frag, | |
struct.unpack('I', header[67:71])[0], | |
- zlib.crc32(header[:59]), | |
+ crc_zlib(header[:59]), | |
crc_alt(header[:59]), | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment