VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-22 15:52:28 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-23 22:49:51 (GMT)
commit9376bc8f5147c892769bddfc738563b9790d4f07 (patch)
treefdb75e5e959cfdf02337d8e5bef5c99c857028c4 /src
parent351daf13001dfdd4427fb5ce4ff41d98e4f7b45f (diff)
downloadVeraCrypt-9376bc8f5147c892769bddfc738563b9790d4f07.zip
VeraCrypt-9376bc8f5147c892769bddfc738563b9790d4f07.tar.gz
Windows: Add check on size of file container to ensure it's smaller than available free space on disk when this is required.
Diffstat (limited to 'src')
-rw-r--r--src/Common/Language.xml1
-rw-r--r--src/Format/Tcformat.c45
-rw-r--r--src/Format/Tcformat.h2
3 files changed, 44 insertions, 4 deletions
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 9073dc1..9c0e4fa 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -1424,6 +1424,7 @@
<entry lang="en" key="PASSWORD_PASTED_TRUNCATED">Pasted text truncated because the password maximum length is 64 characters</entry>
<entry lang="en" key="PASSWORD_MAXLENGTH_REACHED">Password already reached its maximum length of 64 characters.\nNo additional character is allowed.</entry>
<entry lang="en" key="IDC_SELECT_LANGUAGE_LABEL">Select the language to use during the installation:</entry>
+ <entry lang="en" key="VOLUME_TOO_LARGE_FOR_HOST">ERROR: The size of the file container is larger than the available free space on disk.</entry>
</localization>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="VeraCrypt">
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index 2f8b9b2..f2493b0 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -287,6 +287,9 @@ SYSENC_MULTIBOOT_CFG SysEncMultiBootCfg;
wchar_t SysEncMultiBootCfgOutcome [4096] = {L'N',L'/',L'A',0};
volatile int NonSysInplaceEncStatus = NONSYS_INPLACE_ENC_STATUS_NONE;
+LONGLONG nAvailableFreeSpace = -1;
+BOOL bIsSparseFilesSupportedByHost = FALSE;
+
vector <HostDevice> DeferredNonSysInPlaceEncDevices;
// specific definitions and implementation for support of resume operation
@@ -1538,6 +1541,12 @@ static void VerifySizeAndUpdate (HWND hwndDlg, BOOL bUpdate)
{
if (lTmp * i > (bHiddenVolHost ? TC_MAX_HIDDEN_VOLUME_HOST_SIZE : TC_MAX_VOLUME_SIZE))
bEnable = FALSE;
+ else if (!bDevice && (lTmp * i > nAvailableFreeSpace) && (!bIsSparseFilesSupportedByHost || bHiddenVolHost))
+ {
+ // we check container size against available free space only when creating dynamic volume is not possible
+ // which is the case if filesystem doesn't allow sparce file or if we are creating outer volume of a hidden volume
+ bEnable = FALSE;
+ }
}
}
@@ -3366,14 +3375,23 @@ BOOL GetFileVolSize (HWND hwndDlg, unsigned __int64 *size)
}
-BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
+BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display, LONGLONG *pFreeSpaceValue, BOOL* pbIsSparceFilesSupported)
{
+ if (pFreeSpaceValue)
+ *pFreeSpaceValue = 0;
+
+ if (pbIsSparceFilesSupported)
+ *pbIsSparceFilesSupported = FALSE;
+
if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
{
LARGE_INTEGER lDiskFree;
lDiskFree.QuadPart = nMaximumHiddenVolSize;
+ if (pFreeSpaceValue)
+ *pFreeSpaceValue = nMaximumHiddenVolSize;
+
if (display)
PrintFreeSpace (hwndTextBox, NULL, &lDiskFree);
@@ -3382,6 +3400,7 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
else if (bDevice == FALSE)
{
wchar_t root[TC_MAX_PATH];
+ DWORD fileSystemFlags = 0;
ULARGE_INTEGER free;
if (!GetVolumePathName (szFileName, root, ARRAYSIZE (root)))
@@ -3390,6 +3409,14 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
return FALSE;
}
+ if ( pbIsSparceFilesSupported
+ && GetVolumeInformation (root, NULL, 0, NULL, NULL, &fileSystemFlags, NULL, 0)
+ && (fileSystemFlags & FILE_SUPPORTS_SPARSE_FILES)
+ )
+ {
+ *pbIsSparceFilesSupported = TRUE;
+ }
+
if (!GetDiskFreeSpaceEx (root, &free, 0, 0))
{
if (display)
@@ -3402,6 +3429,9 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
LARGE_INTEGER lDiskFree;
lDiskFree.QuadPart = free.QuadPart;
+ if (pFreeSpaceValue)
+ *pFreeSpaceValue = free.QuadPart;
+
if (display)
PrintFreeSpace (hwndTextBox, root, &lDiskFree);
@@ -3463,6 +3493,9 @@ BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display)
nVolumeSize = lDiskFree.QuadPart;
+ if (pFreeSpaceValue)
+ *pFreeSpaceValue = lDiskFree.QuadPart;
+
if (display)
nMultiplier = PrintFreeSpace (hwndTextBox, szDiskFile, &lDiskFree);
@@ -4169,7 +4202,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
SendMessage (GetDlgItem (hwndDlg, IDC_SPACE_LEFT), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_SIZEBOX), EM_LIMITTEXT, 12, 0);
- if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), TRUE))
+ if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), TRUE, &nAvailableFreeSpace, &bIsSparseFilesSupportedByHost))
{
nUIVolumeSize=0;
nVolumeSize=0;
@@ -7348,7 +7381,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (bDevice)
{
- if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), FALSE))
+ if(!QueryFreeSpace (hwndDlg, GetDlgItem (hwndDlg, IDC_SPACE_LEFT), FALSE, NULL, NULL))
{
MessageBoxW (hwndDlg, GetString ("CANT_GET_VOLSIZE"), lpszTitle, ICON_HAND);
NormalCursor ();
@@ -8315,6 +8348,12 @@ retryCDDriveCheck:
quickFormat = IsButtonChecked (GetDlgItem (hCurPage, IDC_QUICKFORMAT));
+ if (!quickFormat && !bDevice && !(bHiddenVol && !bHiddenVolHost) && (nVolumeSize > (ULONGLONG) nAvailableFreeSpace))
+ {
+ Error("VOLUME_TOO_LARGE_FOR_HOST", hwndDlg);
+ bVolTransformThreadToRun = FALSE;
+ return 1;
+ }
if (!bHiddenVol && IsHiddenOSRunning())
{
diff --git a/src/Format/Tcformat.h b/src/Format/Tcformat.h
index 183f17f..caaf2c2 100644
--- a/src/Format/Tcformat.h
+++ b/src/Format/Tcformat.h
@@ -42,7 +42,7 @@ static void LoadPage ( HWND hwndDlg , int nPageNo );
__int64 PrintFreeSpace ( HWND hwndTextBox , wchar_t *lpszDrive , PLARGE_INTEGER lDiskFree );
void DisplaySizingErrorText ( HWND hwndTextBox );
void EnableDisableFileNext ( HWND hComboBox , HWND hMainButton );
-BOOL QueryFreeSpace ( HWND hwndDlg , HWND hwndTextBox , BOOL display );
+BOOL QueryFreeSpace (HWND hwndDlg, HWND hwndTextBox, BOOL display, LONGLONG *pFreeSpaceValue, BOOL* pbIsSparseFilesSupported);
static BOOL FinalPreTransformPrompts (void);
void UpdateLastDialogId (void);
void HandleOldAssignedDriveLetter (void);