From 142c29e68b5399ebe3df2252c7516b380dda215a Mon Sep 17 00:00:00 2001 From: chenxin128 Date: Mon, 18 Sep 2023 12:43:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dota=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=EF=BC=8C=E6=97=A7=E6=95=B0=E6=8D=AE=E9=87=87?= =?UTF-8?q?=E7=94=A8GCM=E8=A7=A3=E5=AF=86=E5=8F=AF=E8=83=BD=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E7=9A=84substr=E5=BC=82=E5=B8=B8=20Signed-off-by:=20c?= =?UTF-8?q?henxin128=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenxin128 --- crypto/encryptor.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crypto/encryptor.cc b/crypto/encryptor.cc index b06f67974d..2b6e6e57f7 100644 --- a/crypto/encryptor.cc +++ b/crypto/encryptor.cc @@ -147,14 +147,20 @@ bool Encryptor::CryptString(bool do_encrypt, base::make_span(out_ptr, out_size), &tag); } else { // Get the tag that we attached with cipher during encryption from input + if (input.length() <= GCM_TAG_SIZE) { + LOG(WARNING) << "input size less than gcm tag size"; + return false; + } tag = std::string(input.substr(input.length() - GCM_TAG_SIZE, GCM_TAG_SIZE)); // Get the cipher part only from input std::string ciphertext = std::string( input.substr(0, input.length() - GCM_TAG_SIZE)); const size_t output_size = ciphertext.length(); - CHECK_GT(output_size, 0u); - CHECK_GT(output_size + 1, ciphertext.length()); + if (output_size + 1 <= ciphertext.length()) { + LOG(WARNING) << "output size occur overflow"; + return false; + } out_ptr = reinterpret_cast(base::WriteInto(&result, output_size + 1)); len = DecryptGCM(ciphertext, base::make_span(out_ptr, output_size), &tag); -- Gitee