[clam-devel] Two issues found by Valgrind

Daniel Glöckner daniel-gl at gmx.net
Sun Jul 20 12:58:50 PDT 2014


Hi,

here are patches for two issues found by Valgrind in CLAM 1.4.0 that
are still present in SVN trunk. Both access memory past the end of
an array. The bug in FourierTransform is more severe as it writes
to the memory location and pairs imaginary and real part of unrelated
spectral components.

  Daniel
-------------- next part --------------
diff -rwud CLAM-1.4.0.orig/src/Processing/Analysis/Tonal/FourierTransform.cxx CLAM-1.4.0/src/Processing/Analysis/Tonal/FourierTransform.cxx
--- CLAM-1.4.0.orig/src/Processing/Analysis/Tonal/FourierTransform.cxx	2007-07-30 22:33:31.000000000 +0200
+++ CLAM-1.4.0/src/Processing/Analysis/Tonal/FourierTransform.cxx	2014-07-20 13:58:35.862218133 +0200
@@ -137,7 +137,7 @@
 			spectrum[i] = complexOutput[i/2][0];
 			spectrum[i+1] = - complexOutput[i/2][1];
 		}
-		for (int i=1; i<mFrameSize; i+=2)
+		for (int i=2; i<mFrameSize; i+=2)
 		{
 			unsigned j = mFrameSize*2-i;
 			spectrum[j] = complexOutput[i/2][0];
-------------- next part --------------
diff -rwud CLAM-1.4.0.orig/src/Processing/Analysis/Tonal/ChordSegmentator.hxx CLAM-1.4.0/src/Processing/Analysis/Tonal/ChordSegmentator.hxx
--- CLAM-1.4.0.orig/src/Processing/Analysis/Tonal/ChordSegmentator.hxx	2008-12-12 13:36:48.000000000 +0100
+++ CLAM-1.4.0/src/Processing/Analysis/Tonal/ChordSegmentator.hxx	2014-07-20 14:12:57.439111882 +0200
@@ -202,8 +202,8 @@
 		
 		std::vector<double> onsets = _segmentation.onsets();
 		std::vector<double> offsets = _segmentation.offsets();
-		unsigned lastSegment = onsets.size();
-		CLAM_ASSERT(segment<lastSegment, "changeChordIfSegmentTooSmall: Accessing a segment beyond lastSegment");
+		unsigned lastSegment = onsets.size() - 1;
+		CLAM_ASSERT(segment<=lastSegment, "changeChordIfSegmentTooSmall: Accessing a segment beyond lastSegment");
 
 		if(offsets[segment]-onsets[segment] < minSegmentLength)
 		{


More information about the clam-devel mailing list