diff --git a/AUTHORS b/AUTHORS index 78e8268560..1ace9ffce2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -143,6 +143,7 @@ Also thanks to: * Riderr3 * riiga * Rikhardur Bjarni Einarsson (WolfGaming) + * Robert Nordan (robpvn) * Sascha Biedermann (bidifx) * Sean Hunt (coppro) * Shawn Collins (UberWaffe) diff --git a/OpenRA.Mods.Common/FileFormats/WavReader.cs b/OpenRA.Mods.Common/FileFormats/WavReader.cs index 564e3437fc..76e9e7f381 100644 --- a/OpenRA.Mods.Common/FileFormats/WavReader.cs +++ b/OpenRA.Mods.Common/FileFormats/WavReader.cs @@ -51,10 +51,11 @@ namespace OpenRA.Mods.Common.FileFormats break; // Break if we aligned with end of stream var blockType = s.ReadASCII(4); + var chunkSize = s.ReadUInt32(); + switch (blockType) { case "fmt ": - var fmtChunkSize = s.ReadInt32(); var audioFormat = s.ReadInt16(); audioType = (WaveType)audioFormat; @@ -67,25 +68,24 @@ namespace OpenRA.Mods.Common.FileFormats blockAlign = s.ReadInt16(); sampleBits = s.ReadInt16(); lengthInSeconds = (float)(s.Length * 8) / (channels * sampleRate * sampleBits); - s.Position += fmtChunkSize - 16; + s.Position += chunkSize - 16; // Ignoring any optional extra params break; case "fact": - var chunkSize = s.ReadInt32(); uncompressedSize = s.ReadInt32(); - s.Position += chunkSize - 4; + s.Position += chunkSize - 4; // Ignoring other formats than ADPCM, fact chunk not in standard PCM files break; case "data": - dataSize = s.ReadInt32(); + if (s.Position + chunkSize > s.Length) + chunkSize = (uint)(s.Length - s.Position); // Handle defective data chunk size by assuming it's the remainder of the file + dataOffset = s.Position; - s.Position += dataSize; + dataSize = (int)chunkSize; + s.Position += chunkSize; break; case "LIST": case "cue ": - var listCueChunkSize = s.ReadInt32(); - s.Position += listCueChunkSize; - break; default: - s.Position = s.Length; // Skip to end of stream + s.Position += chunkSize; // Ignoring chunks we don't want to/know how to handle break; } }