Merge bitcoin/bitcoin#31655: refactor: Avoid UB in SHA3_256::Write

fabeca3458 refactor: Avoid UB in SHA3_256::Write (MarcoFalke)
fad4032b21 refactor: Drop unused UCharCast (MarcoFalke)

Pull request description:

  It is UB to apply a distance to a pointer or iterator further than the
  end itself, even if the distance is (partially) revoked later on.

  Fix the issue by advancing the data pointer at most to the end.

  This fix is required to adopt C++ safe buffers https://github.com/bitcoin/bitcoin/issues/31272.

  Also included is a somewhat unrelated commit.

ACKs for top commit:
  sipa:
    utACK fabeca3458
  theuni:
    utACK fabeca3458
  hebasto:
    ACK fabeca3458.

Tree-SHA512: 78c53691322b72c3ba9c25ec94eec275dbbbc3049b0ad45e7d9fb2df0afbbaa905b0d8fa7106a3582f937bb1dc15a7592c4ad2d80fe4cff1062a3acfd3638f08
This commit is contained in:
merge-script
2025-01-16 12:20:05 +00:00
5 changed files with 11 additions and 11 deletions

View File

@@ -603,7 +603,7 @@ void BerkeleyRODatabase::Open()
// Read subdatabase page number
// It is written as a big endian 32 bit number
uint32_t main_db_page = ReadBE32(UCharCast(std::get<DataRecord>(page.records.at(1)).data.data()));
uint32_t main_db_page = ReadBE32(std::get<DataRecord>(page.records.at(1)).data.data());
// The main database is in a page that doesn't exist
if (main_db_page > outer_meta.last_page) {