From b362ef6bfcb76535584d43c99ec0e3766f7cef35 Mon Sep 17 00:00:00 2001 From: Johannes Schultz Date: Tue, 26 Nov 2024 20:06:26 +0000 Subject: [PATCH] Merged revision(s) 22316 from trunk/OpenMPT: [Mod] MOD: When checking if only the "official" part of the order list should be loaded, round down the file size to an even number. There is at least one MOD file in the wild with an odd file size that needs this quirk, and MOD files can technically not have an odd size anyway. ........ git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@22317 56274372-70c3-4bfc-bfc3-4c3a0b034d27 --- soundlib/Load_mod.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/soundlib/Load_mod.cpp b/soundlib/Load_mod.cpp index aaa601f1cd8..5e35202d2cf 100644 --- a/soundlib/Load_mod.cpp +++ b/soundlib/Load_mod.cpp @@ -617,8 +617,12 @@ static PATTERNINDEX GetNumPatterns(FileReader &file, ModSequence &Order, ORDERIN const size_t patternStartOffset = file.GetPosition(); const size_t sizeWithoutPatterns = totalSampleLen + patternStartOffset; const size_t sizeWithOfficialPatterns = sizeWithoutPatterns + officialPatterns * numChannels * 256; + // There are some WOW files with an extra byte at the end, and also a MOD file (idntmind.mod, MD5 a3af5c3e1af269e32dfb6677c41c8453, SHA1 4884717c298575f9884b2211c762bb1725f73743) + // where only the "official" patterns should be counted but the file also has an extra byte at the end. + // Since MOD files can technically not have an odd file size, we just always round the actual file size down. + const auto fileSize = file.GetLength() & ~1; - if(wowSampleLen && (wowSampleLen + patternStartOffset) + numPatterns * 8 * 256 == (file.GetLength() & ~1)) + if(wowSampleLen && (wowSampleLen + patternStartOffset) + numPatterns * 8 * 256 == fileSize) { // Check if this is a Mod's Grave WOW file... WOW files use the M.K. magic but are actually 8CHN files. // We do a simple pattern validation as well for regular MOD files that have non-module data attached at the end @@ -627,7 +631,7 @@ static PATTERNINDEX GetNumPatterns(FileReader &file, ModSequence &Order, ORDERIN if(ValidateMODPatternData(file, 16, true)) numChannels = 8; file.Seek(patternStartOffset); - } else if(numPatterns != officialPatterns && (validateHiddenPatterns || sizeWithOfficialPatterns == file.GetLength())) + } else if(numPatterns != officialPatterns && (validateHiddenPatterns || sizeWithOfficialPatterns == fileSize)) { // 15-sample SoundTracker specifics: // Fix SoundTracker modules where "hidden" patterns should be ignored. @@ -657,7 +661,7 @@ static PATTERNINDEX GetNumPatterns(FileReader &file, ModSequence &Order, ORDERIN file.Seek(patternStartOffset); } - if(numPatternsIllegal > numPatterns && sizeWithoutPatterns + numPatternsIllegal * numChannels * 256 == file.GetLength()) + if(numPatternsIllegal > numPatterns && sizeWithoutPatterns + numPatternsIllegal * numChannels * 256 == fileSize) { // Even those illegal pattern indexes (> 128) appear to be valid... What a weird file! // e.g. NIETNU.MOD, where the end of the order list is filled with FF rather than 00, and the file actually contains 256 patterns.