Length of story file at 0x1A does not match the length of my byte array

Hello all. I’m playing around with reading Z-machine story files for the first time in Java. I’ve got the following function which reads a word from the memory

int valueInMemory = (data[address] << 8 | (data[address + 1] & 0xff)) & 0xffff;

data is the story file read inn as a byte[]

Path path = Paths.get(filePath);
byte[] data = Files.readAllBytes(path);

When i get the length from memory address 0x1A using this function I get that the length is 31231. Because the story file is an inform 5 file, I multiply this with 4 and get a length of 124924. Now the thing that confuses me is that if I run data.length in Java, I get back 124928. I expected this to be the same, but its actually 4 bytes larger. Is this to be expected?

124928 is an exact multiple of 256, could it be padding? I don’t think that’s required, but it’s not too surprising either. Which story file is it?

Admitably I just grabbed a random game off of if-archive. 7doctors from here: https://ifarchive.org/indexes/if-archiveXgamesXzcode.html

I downloaded another z5 game from there (905.z5) and the difference there is larger. The story file reports it as being 86672, wheras the java byte[] array is 87040 in length, which interestingly is also an exact multiple of 256. So padding may definately be a possibility.

The complete code is here by the way if that is of any interest:

It’s very basic at the moment.

1 Like

When you say it’s an Inform 5 file, I assume you mean it’s Z-machine version 5 file. Then it makes sense to mutiply the stored length by 4.

Z-machine files are often padded to a length which is a multiple of 256 or 512 bytes. The padding may consist of 0-bytes or other values. The padding is not to be considered part of the story data. When calculating the checksum for the file, the padding data must not be included either.

1 Like

You are absolutely right. I’d never really heard of a Z-machine before this week, so the terminology is very much new to me.

In that case it makes sense. I assume this padding is always at the end? Perhaps I should create a new array without the padding in my code :thinking:.

Thanks for the help. Was not expecting to get a solution so fast :smile:

Yes the padding is always at the end.