mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-10-22 06:12:35 +00:00
Unix: snapshot token import lengths before allocation
Use a single file-length measurement for both the non-empty check and the vector allocation in GUI and text token imports. Reject lengths exceeding vector::max_size before converting to size_t, while retaining the cleanup guard before reading.
This commit is contained in:
@@ -146,9 +146,12 @@ namespace VeraCrypt
|
||||
File keyfile;
|
||||
keyfile.Open (keyfilePath, File::OpenRead, File::ShareReadWrite, File::PreserveTimestamps);
|
||||
|
||||
if (keyfile.Length() > 0)
|
||||
const uint64 keyfileSize = keyfile.Length();
|
||||
if (keyfileSize > 0)
|
||||
{
|
||||
vector <uint8> keyfileData (keyfile.Length());
|
||||
if (keyfileSize > vector <uint8>().max_size())
|
||||
throw ParameterTooLarge (SRC_POS, keyfilePath);
|
||||
vector <uint8> keyfileData (static_cast <size_t> (keyfileSize));
|
||||
finally_do_arg (
|
||||
vector <uint8> *, &keyfileData,
|
||||
{ if (!finally_arg->empty()) burn (&finally_arg->front(), finally_arg->size()); }
|
||||
|
||||
@@ -1357,9 +1357,12 @@ namespace VeraCrypt
|
||||
File keyfile;
|
||||
keyfile.Open (keyfilePath, File::OpenRead, File::ShareReadWrite, File::PreserveTimestamps);
|
||||
|
||||
if (keyfile.Length() > 0)
|
||||
const uint64 keyfileSize = keyfile.Length();
|
||||
if (keyfileSize > 0)
|
||||
{
|
||||
vector <uint8> keyfileData (keyfile.Length());
|
||||
if (keyfileSize > vector <uint8>().max_size())
|
||||
throw ParameterTooLarge (SRC_POS, FilePath (keyfilePath));
|
||||
vector <uint8> keyfileData (static_cast <size_t> (keyfileSize));
|
||||
finally_do_arg (
|
||||
vector <uint8> *, &keyfileData,
|
||||
{ if (!finally_arg->empty()) burn (&finally_arg->front(), finally_arg->size()); }
|
||||
|
||||
Reference in New Issue
Block a user