From 96dc02b249389c17c381e67be2931d7e4d66bbd9 Mon Sep 17 00:00:00 2001 From: joevt Date: Mon, 1 Jan 2024 04:41:23 -0800 Subject: [PATCH] atahd: Make sure disk is not too big. --- devices/common/ata/atahd.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/devices/common/ata/atahd.cpp b/devices/common/ata/atahd.cpp index 73cf02f..131c6d8 100644 --- a/devices/common/ata/atahd.cpp +++ b/devices/common/ata/atahd.cpp @@ -63,11 +63,15 @@ int AtaHardDisk::device_postinit() { void AtaHardDisk::insert_image(std::string filename) { if (!this->hdd_img.open(filename)) { - ABORT_F("%s: could not open image file", this->name.c_str()); + ABORT_F("%s: could not open image file \"%s\"", this->name.c_str(), filename.c_str()); } this->img_size = this->hdd_img.size(); - this->total_sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE; + uint64_t sectors = this->hdd_img.size() / ATA_HD_SEC_SIZE; + this->total_sectors = (uint32_t)sectors; + if (sectors != this->total_sectors) { + ABORT_F("%s: image file \"%s\" is too big", this->name.c_str(), filename.c_str()); + } this->calc_chs_params(); }