diff --git a/sim_imd.c b/sim_imd.c index 546b77de..ebaf64f1 100644 --- a/sim_imd.c +++ b/sim_imd.c @@ -1,6 +1,6 @@ /************************************************************************* * * - * Copyright (c) 2007-2020 Howard M. Harte. * + * Copyright (c) 2007-2022 Howard M. Harte. * * https://github.com/hharte * * * * Permission is hereby granted, free of charge, to any person obtaining * @@ -150,7 +150,10 @@ static t_stat diskParse(DISK_INFO *myDisk, uint32 isVerbose) do { sim_debug(myDisk->debugmask, myDisk->device, "start of track %d at file offset %ld\n", myDisk->ntracks, ftell(myDisk->file)); - sim_fread(&imd, 1, 5, myDisk->file); + if (sim_fread(&imd, 1, 5, myDisk->file) != 5) { + return (SCPE_OPENERR); + } + if (feof(myDisk->file)) break; sectorSize = 128 << (imd.sectsize & 0x1f); @@ -169,6 +172,18 @@ static t_stat diskParse(DISK_INFO *myDisk, uint32 isVerbose) myDisk->nsides = imd.head + 1; } + if (imd.head >= MAX_HEAD) { + sim_printf("SIM_IMD: Invalid head %d, a maximum of %d heads are supported.\n", + imd.head, MAX_HEAD); + return (SCPE_IERR); + } + + if (imd.cyl >= MAX_CYL) { + sim_printf("SIM_IMD: Invalid cylinder %d, a maximum of %d cylinders are supported.\n", + imd.cyl, MAX_CYL); + return (SCPE_IERR); + } + myDisk->track[imd.cyl][imd.head].mode = imd.mode; myDisk->track[imd.cyl][imd.head].nsects = imd.nsects; myDisk->track[imd.cyl][imd.head].sectsize = sectorSize;