Skip to content

Commit

Permalink
[Mod] M15: Loosen file rejection heuristics a bit to allow loading of…
Browse files Browse the repository at this point in the history
… schmokk.mod and scramble_2.mod.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@20524 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Apr 8, 2024
1 parent 7e6d5bc commit 3d5e238
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions soundlib/Load_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,9 @@ static bool ValidateHeader(const M15FileHeaders &fileHeaders)
// However, there are quite a few SoundTracker modules in the wild with random
// characters. To still be able to distguish them from other formats, we just reject
// files with *too* many bogus characters. Arbitrary threshold: 48 bogus characters in total
// or more than 5 invalid characters just in the title alone.
// or more than 11 invalid characters just in the title alone (just enough to make scramble_2.mod load).
uint32 invalidChars = CountInvalidChars(fileHeaders.songname);
if(invalidChars > 5)
if(invalidChars > 11)
{
return false;
}
Expand All @@ -1426,10 +1426,13 @@ static bool ValidateHeader(const M15FileHeaders &fileHeaders)

invalidChars += CountInvalidChars(sampleHeader.name);

// schmokk.mod has a non-zero value here but it should not be treated as finetune
if(sampleHeader.finetune != 0)
invalidChars += 16;

// Sanity checks - invalid character count adjusted for ata.mod (MD5 937b79b54026fa73a1a4d3597c26eace, SHA1 3322ca62258adb9e0ae8e9afe6e0c29d39add874)
if(invalidChars > 48
|| sampleHeader.volume > 64
|| sampleHeader.finetune != 0
|| sampleHeader.length > 32768)
{
return false;
Expand Down Expand Up @@ -1537,11 +1540,13 @@ bool CSoundFile::ReadM15(FileReader &file, ModLoadingFlags loadFlags)
file.Seek(20);
for(SAMPLEINDEX smp = 1; smp <= 15; smp++)
{
ModSample &mptSmp = Samples[smp];
MODSampleHeader sampleHeader;
file.ReadStruct(sampleHeader);
ReadSample(sampleHeader, Samples[smp], m_szNames[smp], true);
mptSmp.nFineTune = 0;

totalSampleLen += Samples[smp].nLength;
totalSampleLen += mptSmp.nLength;

if(m_szNames[smp][0] && ((memcmp(m_szNames[smp].buf, "st-", 3) && memcmp(m_szNames[smp].buf, "ST-", 3)) || m_szNames[smp][5] != ':'))
{
Expand All @@ -1552,9 +1557,9 @@ bool CSoundFile::ReadM15(FileReader &file, ModLoadingFlags loadFlags)
// Loop start is always in bytes, not words, so don't trust the auto-fix magic in the sample header conversion (fixes loop of "st-01:asia" in mod.drag 10)
if(sampleHeader.loopLength > 1)
{
Samples[smp].nLoopStart = sampleHeader.loopStart;
Samples[smp].nLoopEnd = sampleHeader.loopStart + sampleHeader.loopLength * 2;
Samples[smp].SanitizeLoops();
mptSmp.nLoopStart = sampleHeader.loopStart;
mptSmp.nLoopEnd = sampleHeader.loopStart + sampleHeader.loopLength * 2;
mptSmp.SanitizeLoops();
}

// UST only handles samples up to 9999 bytes. Master Soundtracker 1.0 and SoundTracker 2.0 introduce 32KB samples.
Expand Down

0 comments on commit 3d5e238

Please sign in to comment.