Skip to content

Commit

Permalink
Merge bitcoin#15950: Do not construct out-of-bound pointers in SHA2 code
Browse files Browse the repository at this point in the history
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 bitcoin#14580. Sadly, it does not fix it.

ACKs for commit c01c06:
  practicalswift:
    utACK c01c065

Tree-SHA512: 47660e00f164f38c36a1ab46e52dd91cd33cfda6a6048d67541c2f8e73c050d4d9d81b5c149bfad281212d52f204f57bebf5b19879dc7a6a5f48aa823fbc2c02
  • Loading branch information
laanwj authored and PastaPastaPasta committed Jul 1, 2021
1 parent 7fa2a56 commit 8804421
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/crypto/ripemd160.cpp
Expand Up @@ -256,7 +256,7 @@ CRIPEMD160& CRIPEMD160::Write(const unsigned char* data, size_t len)
ripemd160::Transform(s, buf);
bufsize = 0;
}
while (end >= data + 64) {
while (end - data >= 64) {
// Process full chunks directly from the source.
ripemd160::Transform(s, data);
bytes += 64;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha1.cpp
Expand Up @@ -163,7 +163,7 @@ CSHA1& CSHA1::Write(const unsigned char* data, size_t len)
sha1::Transform(s, buf);
bufsize = 0;
}
while (end >= data + 64) {
while (end - data >= 64) {
// Process full chunks directly from the source.
sha1::Transform(s, data);
bytes += 64;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha512.cpp
Expand Up @@ -168,7 +168,7 @@ CSHA512& CSHA512::Write(const unsigned char* data, size_t len)
sha512::Transform(s, buf);
bufsize = 0;
}
while (end >= data + 128) {
while (end - data >= 128) {
// Process full chunks directly from the source.
sha512::Transform(s, data);
data += 128;
Expand Down

0 comments on commit 8804421

Please sign in to comment.