mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-06-26 00:29:27 +00:00
Sanity-check .dsk and .nib image raw byte sizes
This commit is contained in:
parent
535abd2c6c
commit
a1e4ba5cc2
14
src/disk.c
14
src/disk.c
|
@ -18,6 +18,9 @@
|
|||
|
||||
#define PHASE_BYTES 3328
|
||||
|
||||
#define NIB_SIZE 232960
|
||||
#define DSK_SIZE 143360
|
||||
|
||||
static unsigned char slot6_rom[256];
|
||||
static int slot6_rom_loaded = 0;
|
||||
|
||||
|
@ -136,7 +139,7 @@ void c_eject_6(int drive) {
|
|||
if (disk6.disk[drive].compressed)
|
||||
{
|
||||
// foo.dsk -> foo.dsk.gz
|
||||
const char* const err = def(disk6.disk[drive].file_name);
|
||||
const char* const err = def(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
|
||||
if (err)
|
||||
{
|
||||
ERRLOG("OOPS: An error occurred when attempting to compress a disk image : %s", err);
|
||||
|
@ -177,7 +180,14 @@ int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
|||
char *file_name = strdup(raw_file_name);
|
||||
if (is_gz(file_name))
|
||||
{
|
||||
const char* const err = inf(file_name); // foo.dsk.gz -> foo.dsk
|
||||
int rawcount = 0;
|
||||
const char *err = inf(file_name, &rawcount); // foo.dsk.gz -> foo.dsk
|
||||
if (!err) {
|
||||
int expected = is_nib(file_name) ? NIB_SIZE : DSK_SIZE;
|
||||
if (rawcount != expected) {
|
||||
err = "disk image is not expected size!";
|
||||
}
|
||||
}
|
||||
if (err)
|
||||
{
|
||||
ERRLOG("OOPS: An error occurred when attempting to inflate/load a disk image : %s", err);
|
||||
|
|
|
@ -48,7 +48,7 @@ static const char* const _gzerr(gzFile gzf)
|
|||
for processing, Z_VERSION_ERROR if the version of zlib.h and the version of
|
||||
the library linked do not match, or Z_ERRNO if there is an error reading or
|
||||
writing the files. */
|
||||
const char* const def(const char* const src)
|
||||
const char *def(const char* const src, const int expected_bytecount)
|
||||
{
|
||||
unsigned char buf[CHUNK];
|
||||
FILE *source = NULL;
|
||||
|
@ -58,6 +58,7 @@ const char* const def(const char* const src)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int bytecount = 0;
|
||||
int ret = UNKNOWN_ERR;
|
||||
do {
|
||||
source = fopen(src, "r");
|
||||
|
@ -96,10 +97,16 @@ const char* const def(const char* const src)
|
|||
ERRLOG("OOPS gzwrite ...");
|
||||
break;
|
||||
}
|
||||
bytecount += written;
|
||||
}
|
||||
|
||||
if (feof(source)) {
|
||||
ret = Z_OK;
|
||||
if (bytecount != expected_bytecount) {
|
||||
ERRLOG("OOPS did not write expected_bytecount of %d ... apparently wrote %d", expected_bytecount, bytecount);
|
||||
ret = UNKNOWN_ERR;
|
||||
} else {
|
||||
ret = Z_OK;
|
||||
}
|
||||
break; // finished deflating
|
||||
}
|
||||
} while (1);
|
||||
|
@ -130,7 +137,7 @@ const char* const def(const char* const src)
|
|||
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
|
||||
the version of the library linked do not match, or Z_ERRNO if there
|
||||
is an error reading or writing the files. */
|
||||
const char* const inf(const char* const src)
|
||||
const char *inf(const char* const src, int *rawcount)
|
||||
{
|
||||
unsigned char buf[CHUNK];
|
||||
gzFile gzsource = NULL;
|
||||
|
@ -140,6 +147,9 @@ const char* const inf(const char* const src)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (rawcount) {
|
||||
*rawcount = 0;
|
||||
}
|
||||
int ret = UNKNOWN_ERR;
|
||||
do {
|
||||
gzsource = gzopen(src, "rb");
|
||||
|
@ -180,7 +190,9 @@ const char* const inf(const char* const src)
|
|||
ERRLOG("OOPS fwrite ...");
|
||||
break;
|
||||
}
|
||||
|
||||
if (rawcount) {
|
||||
*rawcount += buflen;
|
||||
}
|
||||
fflush(dest);
|
||||
} while (1);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
const char* const inf(const char* const source); // source : foo.dsk.gz --> foo.dsk
|
||||
const char* const def(const char* const source); // source : foo.dsk --> foo.dsk.gz
|
||||
const char* inf(const char* const src, int *rawcount); // src : foo.dsk.gz --> foo.dsk
|
||||
const char* def(const char* const src, const int expected_bytes); // src : foo.dsk --> foo.dsk.gz
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user