Skip to content
Snippets Groups Projects
Commit d2b0705a authored by przydatek's avatar przydatek Committed by Charles Lee
Browse files

Fixing memory-access bug.

PiperOrigin-RevId: 243044973
GitOrigin-RevId: 535dc711b71e5f75571755aa0ae85a2fa14ae222
parent a4f1b0f4
No related branches found
No related tags found
Loading
......@@ -108,14 +108,14 @@ util::StatusOr<std::string> KmsEnvelopeAead::Encrypt(
util::StatusOr<std::string> KmsEnvelopeAead::Decrypt(
absl::string_view ciphertext, absl::string_view associated_data) const {
// Parse the ciphertext.
auto enc_dek_size = BigEndianLoad32(
reinterpret_cast<const uint8_t*>(ciphertext.data()));
if (ciphertext.size() < kEncryptedDekPrefixSize ||
enc_dek_size > ciphertext.size() - kEncryptedDekPrefixSize) {
if (ciphertext.size() < kEncryptedDekPrefixSize) {
return util::Status(util::error::INVALID_ARGUMENT,
"ciphertext too short");
}
if (enc_dek_size < 0) {
auto enc_dek_size = BigEndianLoad32(
reinterpret_cast<const uint8_t*>(ciphertext.data()));
if (enc_dek_size > ciphertext.size() - kEncryptedDekPrefixSize ||
enc_dek_size < 0) {
return util::Status(util::error::INVALID_ARGUMENT,
"invalid ciphertext");
}
......
......@@ -107,14 +107,14 @@ TEST(KmsEnvelopeAeadTest, DecryptionErrors) {
HasSubstr("too short")));
// Short ciphertext.
decrypt_result = aead->Decrypt("short", aad);
decrypt_result = aead->Decrypt("sh", aad);
EXPECT_THAT(decrypt_result.status(), StatusIs(util::error::INVALID_ARGUMENT,
HasSubstr("too short")));
// Truncated ciphertext.
decrypt_result = aead->Decrypt(ct.substr(2), aad);
EXPECT_THAT(decrypt_result.status(), StatusIs(util::error::INVALID_ARGUMENT,
HasSubstr("too short")));
HasSubstr("invalid")));
// Corrupted ciphertext.
auto ct_copy = ct;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment