Fix a signed shift overflow in sha256_transform() #113
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:ubsan-sha256-shift"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The message bytes were promoted to int before the shift by 24, which overflows for every byte of 0x80 and above: undefined behaviour that UBSan reports (
sha256.c:49:19: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'). Widen them to WORD first. The digest does not change.Tested: SHA-256 of "abc" and of 64 bytes of 0xff, built with
-fsanitize=undefined -fno-sanitize-recover=all: master stops at the shift; with this commit both digests run clean and equal Python's hashlib (ba7816bf…15ad,8667e718…d1f7).Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA