VirtualBox

Changeset 72574 in vbox


Ignore:
Timestamp:
Jun 15, 2018 9:22:20 PM (6 years ago)
Author:
vboxsync
Message:

Storage/VHD: Stay within possible limits of the VDH spec for the block allocation table and reject images violating the spec, missing status code check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VHD.cpp

    r69500 r72574  
    4040#define VHD_SECTOR_SIZE 512
    4141#define VHD_BLOCK_SIZE  (2 * _1M)
     42
     43/** The maximum VHD size is 2TB due to the 32bit sector numbers in the BAT.
     44 * Note that this is the maximum file size including all footers and headers
     45 * and not the maximum virtual disk size presented to the guest.
     46 */
     47#define VHD_MAX_SIZE    (2 * _1T)
     48/** Maximum number of 512 byte sectors for a VHD image. */
     49#define VHD_MAX_SECTORS ((uint32_t)(VHD_MAX_SIZE / VHD_SECTOR_SIZE))
    4250
    4351/* This is common to all VHD disk types and is located at the end of the image */
     
    748756    AssertMsg(!(pImage->cbDataBlock % VHD_SECTOR_SIZE), ("%s: Data block size is not a multiple of %!\n", __FUNCTION__, VHD_SECTOR_SIZE));
    749757
     758    /* Bail out if the number of BAT entries exceeds the number of sectors for a maximum image. */
     759    if (pImage->cBlockAllocationTableEntries > VHD_MAX_SECTORS)
     760        return VERR_VD_VHD_INVALID_HEADER;
     761
    750762    pImage->cSectorsPerDataBlock = pImage->cbDataBlock / VHD_SECTOR_SIZE;
    751763    LogFlowFunc(("SectorsPerDataBlock=%u\n", pImage->cSectorsPerDataBlock));
     
    780792                               uBlockAllocationTableOffset, pBlockAllocationTable,
    781793                               pImage->cBlockAllocationTableEntries * sizeof(uint32_t));
     794    if (RT_FAILURE(rc))
     795        return rc;
    782796
    783797    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette