Skip to content

Commit 3d6dd4b

Browse files
committed
Storage/VDI.cpp: Relatively tight allocation block size sanity check on image creation, quite forgiving check on open to allow even strange values. bugref:11113
svn:sync-xref-src-repo-rev: r174551
1 parent be49d64 commit 3d6dd4b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/VBox/Storage/VDI.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: VDI.cpp 112403 2026-01-11 19:29:08Z knut.osmundsen@oracle.com $ */
1+
/* $Id: VDI.cpp 114715 2026-07-15 18:04:01Z klaus.espenlaub@oracle.com $ */
22
/** @file
33
* Virtual Disk Image (VDI), Core Code.
44
*/
@@ -573,6 +573,12 @@ static int vdiSetupImageState(PVDIIMAGEDESC pImage, unsigned uImageFlags, const
573573
{
574574
int rc = VINF_SUCCESS;
575575

576+
if ( cbAllocationBlock < VDI_IMAGE_DEFAULT_BLOCK_SIZE / 2
577+
|| cbAllocationBlock > VDI_IMAGE_DEFAULT_BLOCK_SIZE * 8
578+
|| !(cbAllocationBlock & (cbAllocationBlock - 1)))
579+
return vdIfError(pImage->pIfError, VERR_VD_VDI_COMMENT_TOO_LONG, RT_SRC_POS,
580+
N_("VDI: Image with invalid allocation block size in '%s'"), pImage->pszFilename);
581+
576582
vdiInitPreHeader(&pImage->PreHeader);
577583
vdiInitHeader(&pImage->Header, uImageFlags, pszComment, cbSize, cbAllocationBlock, 0,
578584
cbDataAlign);
@@ -985,6 +991,14 @@ static int vdiOpenImage(PVDIIMAGEDESC pImage, unsigned uOpenFlags)
985991
{
986992
rc = vdiImageReadHeader(pImage);
987993
if (RT_SUCCESS(rc))
994+
{
995+
/* Intentionally be much more forgiving than when creating new images. */
996+
if ( getImageBlockSize(&pImage->Header) < VDI_IMAGE_DEFAULT_BLOCK_SIZE / 8
997+
|| getImageBlockSize(&pImage->Header) > VDI_IMAGE_DEFAULT_BLOCK_SIZE * 128)
998+
rc = vdIfError(pImage->pIfError, VERR_VD_VDI_COMMENT_TOO_LONG, RT_SRC_POS,
999+
N_("VDI: Image with invalid allocation block size in '%s'"), pImage->pszFilename);
1000+
}
1001+
if (RT_SUCCESS(rc))
9881002
{
9891003
/* Allocate memory for blocks array. */
9901004
pImage->paBlocks = (PVDIIMAGEBLOCKPOINTER)RTMemAlloc(sizeof(VDIIMAGEBLOCKPOINTER) * getImageBlocks(&pImage->Header));
@@ -1005,7 +1019,7 @@ static int vdiOpenImage(PVDIIMAGEDESC pImage, unsigned uOpenFlags)
10051019
}
10061020
else
10071021
rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS,
1008-
N_("VDI: Error allocating memory for the block table in '%s'"), pImage->pszFilename);;
1022+
N_("VDI: Error allocating memory for the block table in '%s'"), pImage->pszFilename);
10091023
}
10101024
}
10111025
/* else: Do NOT signal an appropriate error here, as the VD layer has the

0 commit comments

Comments
 (0)