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:
Mounir IDRASSI
2026-10-15 00:09:37 +09:00
committed by Mounir IDRASSI
parent c42fb18d59
commit bd8e6a70aa
2 changed files with 10 additions and 4 deletions
@@ -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()); }
+5 -2
View File
@@ -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()); }