Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Reads past end of file with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT #86

Open
Rondom opened this issue Mar 25, 2018 · 3 comments
Open

Reads past end of file with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT #86

Rondom opened this issue Mar 25, 2018 · 3 comments

Comments

@Rondom
Copy link
Contributor

Rondom commented Mar 25, 2018

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:

dumb/src/it/readmod.c

Lines 47 to 50 in 7415127

dumbfile_getnc((char *)buffer, 64 * n_channels * 4, f);
if (dumbfile_error(f))
return -1;

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)
@kode54
Copy link
Owner

kode54 commented Mar 25, 2018

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.

@Rondom
Copy link
Contributor Author

Rondom commented Mar 25, 2018

Thanks for the quick answer.

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

@Rondom Rondom changed the title Read past end of file with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT Reads past end of file with DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT Mar 25, 2018
@kode54
Copy link
Owner

kode54 commented Mar 25, 2018

_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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants