Skip to content

Commit

Permalink
opcode_read: Parse buffer size check was wrong.
Browse files Browse the repository at this point in the history
According to the [z-machine spec](https://inform-fiction.org/zmachine/standards/z1point1/sect15.html#sread) ...

> (Interpreters are asked to halt with a suitable error message if the text
> or parse buffers have length of less than 3 or 6 bytes, respectively: this
> sometimes occurs due to a previous array being overrun, causing bugs which
> are very difficult to find.)

My check is incorrect here; I have no idea where I got 4 in any case from
this text, but also, this number measures _tokens_, not bytes...the buffer
size is actually `2 + 4 * parselen`, so anything larger than zero will be
greater than 6 bytes.

This fixes Moonmist exploding near the start, when it asks you to enter your
name.

Fixes #24.
  • Loading branch information
icculus committed Dec 31, 2023
1 parent 89832e3 commit 5c8d81f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mojozork.c
Expand Up @@ -1333,7 +1333,7 @@ static void opcode_read(void)
const uint8 parselen = *(parse++);

dbg("max parse: %u\n", (unsigned int) parselen);
if (parselen < 4)
if (parselen == 0)
GState->die("parse buffer is too small for reading"); // happens on buffer overflow.

updateStatusBar();
Expand Down

0 comments on commit 5c8d81f

Please sign in to comment.