diff options
author | Rod Smith <rodsmith@rodsbooks.com> | 2022-04-10 10:25:41 -0400 |
---|---|---|
committer | Rod Smith <rodsmith@rodsbooks.com> | 2022-04-10 10:25:41 -0400 |
commit | 6b7486db9927a1b3f6dd9cc84dff54c33a8aef8c (patch) | |
tree | c51f9e52f2b54453cc86fa4f031488fd9834f9c6 | |
parent | 4be26d7228a5dadfd04488618f08a29f0c67dd8c (diff) | |
download | sgdisk-6b7486db9927a1b3f6dd9cc84dff54c33a8aef8c.tar.gz |
Abort load of too-small disk image
-rw-r--r-- | gpt.cc | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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 { |