Fix incorrect max hidden volume size for file containers on CLI (#1338)

Currently the maximum hidden volume size for file containers is
limited by available free space on the device the file container
resides on, which we do not care about. This commit changes so
that only Normal volumes get their `maxVolumeSize` limited by
`AvailableDiskSpace`. Also the --size=max parameter is restricted
from hidden volume creation as there is no way to determine a good
size as we do not mount the outer volume through the CLI process
flow to determine available free space on the outer volume.
This commit is contained in:
Jertzukka 2024-05-08 20:00:09 +03:00 committed by GitHub
parent e96f3035d9
commit 55c3a8dc58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -668,7 +668,7 @@ namespace VeraCrypt
{
parentDir = wxT(".");
}
if (wxDirExists(parentDir) && wxGetDiskSpace (parentDir, nullptr, &diskSpace))
if (options->Type == VolumeType::Normal && wxDirExists(parentDir) && wxGetDiskSpace (parentDir, nullptr, &diskSpace))
{
AvailableDiskSpace = (uint64) diskSpace.GetValue ();
if (maxVolumeSize > AvailableDiskSpace)
@ -678,10 +678,13 @@ namespace VeraCrypt
if (options->Size == (uint64) (-1))
{
if (AvailableDiskSpace)
if (options->Type == VolumeType::Hidden) {
throw_err (_("Please do not use maximum size for hidden volume. As we do not mount the outer volume to determine the available space, it is your responsibility to choose a value so that the hidden volume does not overlap the outer volume."));
}
else if (AvailableDiskSpace)
{
// caller requesting maximum size
// we use maxVolumeSize because it is guaranteed to be less of equal to AvailableDiskSpace
// we use maxVolumeSize because it is guaranteed to be less or equal to AvailableDiskSpace for outer volumes
options->Size = maxVolumeSize;
}
else
@ -702,14 +705,17 @@ namespace VeraCrypt
throw MissingArgument (SRC_POS);
uint64 multiplier = 1024 * 1024;
wxString sizeStr = AskString (options->Type == VolumeType::Hidden ? _("\nEnter hidden volume size (sizeK/size[M]/sizeG/sizeT/max): ") : _("\nEnter volume size (sizeK/size[M]/sizeG.sizeT/max): "));
wxString sizeStr = AskString (options->Type == VolumeType::Hidden ? _("\nEnter hidden volume size (sizeK/size[M]/sizeG/sizeT): ") : _("\nEnter volume size (sizeK/size[M]/sizeG.sizeT/max): "));
if (sizeStr.CmpNoCase(wxT("max")) == 0)
{
multiplier = 1;
if (AvailableDiskSpace)
if (options->Type == VolumeType::Hidden) {
throw_err (_("Please do not use maximum size for hidden volume. As we do not mount the outer volume to determine the available space, it is your responsibility to choose a value so that the hidden volume does not overlap the outer volume."));
}
else if (AvailableDiskSpace)
{
// caller requesting maximum size
// we use maxVolumeSize because it is guaranteed to be less of equal to AvailableDiskSpace
// we use maxVolumeSize because it is guaranteed to be less or equal to AvailableDiskSpace for outer volumes
options->Size = maxVolumeSize;
}
else