dumb icon indicating copy to clipboard operation
dumb copied to clipboard

Reads past end of file with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT

Open Rondom opened this issue 6 years ago • 3 comments

OS: Debian testing Arch: amd64

I noticed that dumb_read_mod fails when called with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT and the attached mod-file from the game Alex the Allegator 4. alex4_once_i_was_an_egg.tar.gz

DUMBFILE *df = dumbfile_open_stdfile(fopen("./alex4_once_i_was_an_egg.mod", "rb"));
DUH *duh = dumb_read_mod(df, DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT);
fprintf(stderr, "dumb_read_mod returned %p\n", duh);
dumbfile_close(df);

I tracked it down to a read past the end of the file here: https://github.com/kode54/dumb/blob/741512775989f2d3a9497167030742797c43e63a/src/it/readmod.c#L47-L50

read of size 20 with 42792 bytes left
read of size 22 with 42772 bytes left
read of size 22 with 42742 bytes left
read of size 22 with 42712 bytes left
read of size 22 with 42682 bytes left
read of size 22 with 42652 bytes left
read of size 22 with 42622 bytes left
read of size 22 with 42592 bytes left
read of size 22 with 42562 bytes left
read of size 22 with 42532 bytes left
read of size 22 with 42502 bytes left
read of size 22 with 42472 bytes left
read of size 22 with 42442 bytes left
read of size 22 with 42412 bytes left
read of size 22 with 42382 bytes left
read of size 22 with 42352 bytes left
read of size 22 with 42322 bytes left
read of size 22 with 42292 bytes left
read of size 22 with 42262 bytes left
read of size 22 with 42232 bytes left
read of size 22 with 42202 bytes left
read of size 22 with 42172 bytes left
read of size 22 with 42142 bytes left
read of size 22 with 42112 bytes left
read of size 22 with 42082 bytes left
read of size 22 with 42052 bytes left
read of size 22 with 42022 bytes left
read of size 22 with 41992 bytes left
read of size 22 with 41962 bytes left
read of size 22 with 41932 bytes left
read of size 22 with 41902 bytes left
read of size 22 with 41872 bytes left
read of size 128 with 41840 bytes left
read of size 5 with 823 bytes left
read of size 5 with 3040 bytes left
read of size 5 with 6420 bytes left
read of size 5 with 8449 bytes left
read of size 5 with 8577 bytes left
read of size 5 with 8705 bytes left
read of size 5 with 8801 bytes left
read of size 5 with 8865 bytes left
read of size 5 with 8929 bytes left
read of size 1024 with 8940 bytes left
read of size 1024 with 7916 bytes left
read of size 1024 with 6892 bytes left
read of size 1024 with 5868 bytes left
read of size 1024 with 4844 bytes left
read of size 1024 with 3820 bytes left
read of size 1024 with 2796 bytes left
read of size 1024 with 1772 bytes left
read of size 1024 with 748 bytes left
dumb_read_mod returned (nil)

Rondom avatar Mar 25 '18 06:03 Rondom

So don't use that mode. It's only provided in case it actually proves useful.

Default mode is to count patterns from the order list. This mode counts all the sample data present in the file, and assumes all the rest of the file is patterns.

kode54 avatar Mar 25 '18 07:03 kode54

Thanks for the quick answer.

It's used by aldmb :-) What is the recommended value for the _restrict parameter, then? 0 or 1?

Rondom avatar Mar 25 '18 08:03 Rondom

_restrict should probably be 1 unless you absolutely know you'll be working with 15 sample modules, which have no identifying signature, so they'll usually succeed on load, even if you pass in invalid data.

kode54 avatar Mar 25 '18 22:03 kode54