1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibCrypto: Fix Hash::MD5's movability

Because MD5 stored a "Bytes {}" wrapper to its internal data buffer,
it was not actually movable. However, its use in several parts of
the system (such as HashManager) assumed it was, leading to crashes.

Fixes #8135
This commit is contained in:
DexesTTP 2021-06-18 18:28:04 +02:00 committed by Ali Mohammad Pur
parent f29036dc98
commit b205c9814a
2 changed files with 4 additions and 9 deletions

View file

@ -58,9 +58,10 @@ void MD5::update(const u8* input, size_t length)
m_count[1] += (u32)length >> 29;
auto part_length = 64 - index;
auto buffer = Bytes { m_data_buffer, sizeof(m_data_buffer) };
if (length >= part_length) {
m_buffer.overwrite(index, input, part_length);
transform(m_buffer.data());
buffer.overwrite(index, input, part_length);
transform(buffer.data());
for (offset = part_length; offset + 63 < length; offset += 64)
transform(&input[offset]);
@ -69,7 +70,7 @@ void MD5::update(const u8* input, size_t length)
}
VERIFY(length < part_length || length - offset <= 64);
m_buffer.overwrite(index, &input[offset], length - offset);
buffer.overwrite(index, &input[offset], length - offset);
}
MD5::DigestType MD5::digest()
{