1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibPDF: Reset encryption key on failed user password attempt

When an attempt is made to provide the user password to a
SecurityHandler a user gets back a boolean result indicating success or
failure on the attempt. However, the SecurityHandler is left in a state
where it thinks it has a user password, regardless of the outcome of the
attempt. This confuses the rest of the system, which continues as if the
provided password is correct, resulting in garbled content.

This commit fixes the situation by resetting the internal fields holding
the encryption key (which is used to determine whether a user password
has been successfully provided) in case of a failed attempt.
This commit is contained in:
Rodrigo Tobar 2022-12-20 14:01:58 +08:00 committed by Andreas Kling
parent dc6a11cf6b
commit bb48a67f84
Notes: sideshowbarker 2024-07-17 03:19:14 +09:00

View file

@ -187,9 +187,14 @@ bool StandardSecurityHandler::try_provide_user_password(StringView password_stri
// handlers of revision 3 or greater), the password supplied is the correct user
// password.
auto u_bytes = m_u_entry.bytes();
bool has_user_password;
if (m_revision >= 3)
return u_bytes.slice(0, 16) == password_buffer.bytes().slice(0, 16);
return u_bytes == password_buffer.bytes();
has_user_password = u_bytes.slice(0, 16) == password_buffer.bytes().slice(0, 16);
else
has_user_password = u_bytes == password_buffer.bytes();
if (!has_user_password)
m_encryption_key = {};
return has_user_password;
}
ByteBuffer StandardSecurityHandler::compute_encryption_key(ByteBuffer password_string)