Skip to content

Commit fd61b9f

Browse files
committed
Merge #15950: Do not construct out-of-bound pointers in SHA2 code
c01c065 Do not construct out-of-bound pointers in SHA512/SHA1/RIPEMD160 code (Pieter Wuille) Pull request description: This looks like an issue in the current SHA256/512 code, where a pointer outside of the area pointed to may be constructed (this is UB in theory, though in practice every supported platform treats pointers as integers). I discovered this while investigating #14580. Sadly, it does not fix it. ACKs for commit c01c06: practicalswift: utACK c01c065 Tree-SHA512: 47660e00f164f38c36a1ab46e52dd91cd33cfda6a6048d67541c2f8e73c050d4d9d81b5c149bfad281212d52f204f57bebf5b19879dc7a6a5f48aa823fbc2c02
2 parents 47ec831 + c01c065 commit fd61b9f

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/crypto/ripemd160.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ CRIPEMD160& CRIPEMD160::Write(const unsigned char* data, size_t len)
256256
ripemd160::Transform(s, buf);
257257
bufsize = 0;
258258
}
259-
while (end >= data + 64) {
259+
while (end - data >= 64) {
260260
// Process full chunks directly from the source.
261261
ripemd160::Transform(s, data);
262262
bytes += 64;

src/crypto/sha1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ CSHA1& CSHA1::Write(const unsigned char* data, size_t len)
163163
sha1::Transform(s, buf);
164164
bufsize = 0;
165165
}
166-
while (end >= data + 64) {
166+
while (end - data >= 64) {
167167
// Process full chunks directly from the source.
168168
sha1::Transform(s, data);
169169
bytes += 64;

src/crypto/sha512.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ CSHA512& CSHA512::Write(const unsigned char* data, size_t len)
168168
sha512::Transform(s, buf);
169169
bufsize = 0;
170170
}
171-
while (end >= data + 128) {
171+
while (end - data >= 128) {
172172
// Process full chunks directly from the source.
173173
sha512::Transform(s, data);
174174
data += 128;

0 commit comments

Comments
 (0)