aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/io.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index 8469a6b..2323700 100644
--- a/src/io.c
+++ b/src/io.c
@@ -20,6 +20,33 @@ static void eof_junk(void) {
fprintf(stderr, "%s: junk at EOF (ignoring)\n", self);
}
+static void check_hdr_size(const char *name, unsigned long size) {
+ const char *desc;
+
+ /* fits on a double-density disk? */
+ if(size < 184320)
+ return;
+
+ /* >= 16MB files are impossible because the decrunch algorithm
+ ignores the high byte of the 4-byte length. */
+ if(size >= 16777216L)
+ desc = "impossibly large (>=16MB)";
+ /* >1MB files are possible (e.g. with a hard drive on SpartaDOS X)
+ but exceedingly rare in the Atari world. */
+ else if(size > 1048576L)
+ desc = "suspiciously large (>1MB)";
+ else
+ desc = "too large for a floppy disk (>180KB)";
+
+ fprintf(stderr, "%s: header #%d %s size is %s.\n",
+ self, headers_read, name, desc);
+}
+
+static void sanity_check_header(void) {
+ check_hdr_size("original", getquad(alf_hdr_origsize0));
+ check_hdr_size("compressed", getquad(alf_hdr_compsize0));
+}
+
/* return 1 if a header is read, 0 if not */
int read_alf_header(void) {
u8 h1, h2;
@@ -48,6 +75,7 @@ int read_alf_header(void) {
if(h2 < 0x0f) die_arc();
if(h2 == 0x0f) {
headers_read++;
+ sanity_check_header();
return 1; /* signature matches */
}
}