From 2d4c56de314ab13e4437bd8b609f0b751066eee8 Mon Sep 17 00:00:00 2001
From: Konstanty Bialkowski <metaplasma@users.sourceforge.net>
Date: Fri, 15 Jul 2011 23:25:03 +1000
Subject: [PATCH] Fix integer overflow (SA45131/A)

---
 libmodplug/src/load_wav.cpp |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libmodplug/src/load_wav.cpp b/libmodplug/src/load_wav.cpp
index 3bcd132..0399cba 100644
--- a/libmodplug/src/load_wav.cpp
+++ b/libmodplug/src/load_wav.cpp
@@ -54,7 +54,7 @@ BOOL CSoundFile::ReadWav(const BYTE *lpStream, DWORD dwMemLength)
 	if ((Patterns[1] = AllocatePattern(64, 4)) == NULL) return TRUE;
 	UINT samplesize = (pfmt->channels * pfmt->bitspersample) >> 3;
 	UINT len = pdata->length, bytelen;
-	if (dwMemPos + len > dwMemLength - 8) len = dwMemLength - dwMemPos - 8;
+	if (len > dwMemLength - 8 - dwMemPos) len = dwMemLength - dwMemPos - 8;
 	len /= samplesize;
 	bytelen = len;
 	if (pfmt->bitspersample >= 16) bytelen *= 2;
-- 
1.7.0.1

