Fix a signed shift overflow in sha256_transform() #113

Merged
vitalif merged 1 commits from koolkhel/vitastor:ubsan-sha256-shift into master 2026-10-27 23:53:59 +03:00
Contributor

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

### 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 - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-10-27 10:26:36 +03:00
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. Widen them to WORD first. The digest does not change.
vitalif merged commit 4e638b2681 into master 2026-10-27 23:53:59 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#113
No description provided.