From d287b81054dd1218e0b856374a983769562e1bf0 Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 29 Aug 2025 23:39:13 +0200 Subject: [PATCH] CD-ROM: Only do the lead out processing on REM SESSION command if session is greater than 1, fixes crashes with arithmetic exception (ie. division by zero). --- src/cdrom/cdrom_image.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/cdrom/cdrom_image.c b/src/cdrom/cdrom_image.c index 902fd2222..44f45bdc4 100644 --- a/src/cdrom/cdrom_image.c +++ b/src/cdrom/cdrom_image.c @@ -1743,28 +1743,27 @@ image_load_cue(cd_image_t *img, const char *cuefile) image_log(img->log, " [LEAD-OUT] Initialization %s\n", success ? "successful" : "failed"); } else if (!strcmp(command, "SESSION")) { - if (!lo_cmd) { - ct = &(img->tracks[lead[2]]); - /* - Mark it this way so file pointers on it are not - going to be adjusted. - */ - last_t = -1; - ct->sector_size = last; - ci = &(ct->idx[1]); - ci->type = INDEX_ZERO; - ci->file = tf; - ci->file_start = 0; - ci->file_length = 0; - ci->length = (2 * 60 * 75) + (30 * 75); - - image_log(img->log, " [LEAD-OUT] Initialization successful\n"); - } - - lo_cmd = 0; session = image_cue_get_number(&space); if (session > 1) { + if (!lo_cmd) { + ct = &(img->tracks[lead[2]]); + /* + Mark it this way so file pointers on it are not + going to be adjusted. + */ + last_t = -1; + ct->sector_size = last; + ci = &(ct->idx[1]); + ci->type = INDEX_ZERO; + ci->file = tf; + ci->file_start = 0; + ci->file_length = 0; + ci->length = (2 * 60 * 75) + (30 * 75); + + image_log(img->log, " [LEAD-OUT] Initialization successful\n"); + } + ct = image_insert_track(img, session - 1, 0xb0); /* Mark it this way so file pointers on it are not @@ -1801,6 +1800,8 @@ image_load_cue(cd_image_t *img, const char *cuefile) } } + lo_cmd = 0; + image_log(img->log, " [SESSION ] Initialization successful\n"); } }