From a17ea8387c6e41b396408ee9b0d576b97cb0f985 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sat, 10 Feb 2024 11:10:00 +1100 Subject: -imagedev/harddriv.cpp: Report unsuitable CHDs rather than crashing. -imagedev/cdrom.cpp: Report unsuitable CHDs as "invalid image" rather than "unsupported operation". --- src/devices/imagedev/cdromimg.cpp | 8 ++--- src/devices/imagedev/harddriv.cpp | 61 +++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/devices/imagedev/cdromimg.cpp b/src/devices/imagedev/cdromimg.cpp index 6078aa79611..a5ceca8b16d 100644 --- a/src/devices/imagedev/cdromimg.cpp +++ b/src/devices/imagedev/cdromimg.cpp @@ -136,7 +136,7 @@ std::pair cdrom_image_device::call_load() m_dvdrom_handle.reset(new dvdrom_file(chd)); else { - err = image_error::UNSUPPORTED; + err = image_error::INVALIDIMAGE; goto error; } } @@ -146,15 +146,15 @@ std::pair cdrom_image_device::call_load() { m_cdrom_handle.reset(new cdrom_file(filename())); } - catch (void *) + catch (...) { try { m_dvdrom_handle.reset(new dvdrom_file(filename())); } - catch (void *) + catch (...) { - err = image_error::UNSUPPORTED; + err = image_error::INVALIDIMAGE; goto error; } } diff --git a/src/devices/imagedev/harddriv.cpp b/src/devices/imagedev/harddriv.cpp index 2d7933919fa..14f4337f9d8 100644 --- a/src/devices/imagedev/harddriv.cpp +++ b/src/devices/imagedev/harddriv.cpp @@ -287,48 +287,59 @@ std::error_condition harddisk_image_device::internal_load_hd() if (m_chd) { // open the hard disk file - m_hard_disk_handle.reset(new hard_disk_file(m_chd)); - if (m_hard_disk_handle) - return std::error_condition(); + try + { + m_hard_disk_handle.reset(new hard_disk_file(m_chd)); + if (m_hard_disk_handle) + return std::error_condition(); + } + catch (...) + { + err = image_error::INVALIDIMAGE; + } + } + else if (!is_open()) + { + err = image_error::UNSPECIFIED; } else { - if (is_open()) - { - uint32_t skip = 0; + uint32_t skip = 0; - // check for 2MG format - if (!memcmp(header, "2IMG", 4)) + if (!memcmp(header, "2IMG", 4)) // check for 2MG format + { + skip = get_u32le(&header[0x18]); + osd_printf_verbose("harddriv: detected 2MG, creator is %c%c%c%c, data at %08x\n", header[4], header[5], header[6], header[7], skip); + } + else if (is_filetype("hdi")) // check for HDI format + { + skip = get_u32le(&header[0x8]); + uint32_t data_size = get_u32le(&header[0xc]); + if (data_size == length() - skip) { - skip = get_u32le(&header[0x18]); - osd_printf_verbose("harddriv: detected 2MG, creator is %c%c%c%c, data at %08x\n", header[4], header[5], header[6], header[7], skip); + osd_printf_verbose("harddriv: detected Anex86 HDI, data at %08x\n", skip); } - // check for HDI format - else if (is_filetype("hdi")) + else { - skip = get_u32le(&header[0x8]); - uint32_t data_size = get_u32le(&header[0xc]); - if (data_size == length() - skip) - { - osd_printf_verbose("harddriv: detected Anex86 HDI, data at %08x\n", skip); - } - else - { - skip = 0; - } + skip = 0; } + } + try + { m_hard_disk_handle.reset(new hard_disk_file(image_core_file(), skip)); if (m_hard_disk_handle) return std::error_condition(); } - - return image_error::UNSPECIFIED; + catch (...) + { + err = image_error::INVALIDIMAGE; + } } /* if we had an error, close out the CHD */ - m_origchd.close(); m_diffchd.close(); + m_origchd.close(); m_chd = nullptr; if (err) -- cgit v1.2.3