Ticket #8990: 0002-partition-offset-check-while-validating.patch

File 0002-partition-offset-check-while-validating.patch, 1.5 KB (added by kushalsingh007, 10 years ago)

Patch for adding offset check for the partition.

  • src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp

    From b1e8f5983ff5d9726867e67d2863ac0ed8a4d067 Mon Sep 17 00:00:00 2001
    From: Kushal Singh <kushal.singh@students.iiit.ac.in>
    Date: Wed, 18 Feb 2015 22:20:04 +0530
    Subject: [PATCH] * Added an offset to ensure ensure that it lies within
     MBRLimit * Fixes 8990 after the value returned by BlockSize() was corrected.
    
    ---
     src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp | 13 +++++++++----
     1 file changed, 9 insertions(+), 4 deletions(-)
    
    diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp
    index d9c1450..aaa9264 100644
    a b PartitionMapAddOn::CreatePartitionHandle(BMutablePartition* partition,  
    9090bool
    9191PartitionMapAddOn::CanInitialize(const BMutablePartition* partition)
    9292{
    93     // If it's big enough, but not too big (ie. larger than 2^32 blocks) we can
    94     // initialize it.
    95     return partition->Size() >= 2 * partition->BlockSize()
    96         && partition->Size() / partition->BlockSize() < UINT32_MAX;
     93    off_t MBRSizeLimit = ((off_t)1 <<32) * partition->BlockSize();
     94        // Limit on size is (MaxSectorCount)*(SectorSize)=(2^32)*(SectorSize).
     95 
     96    // If it's big enough, but not too big (ie. larger than 2^32 blocks) we can
     97    // initialize it. Also, the highest offset of a partition should be lesser
     98    // than MBR size limit.
     99    return partition->Size() >= 2 * partition->BlockSize()
     100        && partition->Size() < MBRSizeLimit
     101        && partition->Offset() < MBRSizeLimit;
    97102}
    98103
    99104