From 6b7486db9927a1b3f6dd9cc84dff54c33a8aef8c Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 10:25:41 -0400 Subject: Abort load of too-small disk image --- gpt.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'gpt.cc') diff --git a/gpt.cc b/gpt.cc index 5ccc5c5..848340b 100644 --- a/gpt.cc +++ b/gpt.cc @@ -886,8 +886,16 @@ int GPTData::LoadPartitions(const string & deviceFilename) { break; } // switch - if (allOK) + if (allOK) { CheckGPTSize(); + // Below is unlikely to happen on real disks, but could happen if + // the user is manipulating a truncated image file.... + if (diskSize <= GetTableSizeInSectors() * 2 + 3) { + allOK = 0; + cout << "Disk is too small to hold GPT data (" << diskSize + << " sectors)! Aborting!\n"; + } + } myDisk.Close(); ComputeAlignment(); } else { -- cgit v1.2.1