From 2e1b6b67b37c958a6c8d85626cbbfd4e23f9294e Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Tue, 7 Aug 2012 14:57:45 -0500
Subject: libmikmod 3.1.12

---
 abs/extra/libmikmod/PKGBUILD                       |  37 +++++--
 .../libmikmod/libmikmod-3.1.12-64bit-fix.diff      |  47 +++++++++
 .../libmikmod/libmikmod-3.1.12-exitcrash-fix.diff  |  21 ++++
 .../libmikmod-3.1.12-loopingvolume-fix.diff        |  15 +++
 .../libmikmod/libmikmod-3.1.12-md_sngchn-fix.diff  | 112 +++++++++++++++++++++
 abs/extra/libmikmod/libmikmod-CVE-2009-0179.patch  |  33 ++++++
 abs/extra/libmikmod/libmikmod.install              |  18 ++++
 7 files changed, 275 insertions(+), 8 deletions(-)
 create mode 100644 abs/extra/libmikmod/libmikmod-3.1.12-64bit-fix.diff
 create mode 100644 abs/extra/libmikmod/libmikmod-3.1.12-exitcrash-fix.diff
 create mode 100644 abs/extra/libmikmod/libmikmod-3.1.12-loopingvolume-fix.diff
 create mode 100644 abs/extra/libmikmod/libmikmod-3.1.12-md_sngchn-fix.diff
 create mode 100644 abs/extra/libmikmod/libmikmod-CVE-2009-0179.patch
 create mode 100644 abs/extra/libmikmod/libmikmod.install

diff --git a/abs/extra/libmikmod/PKGBUILD b/abs/extra/libmikmod/PKGBUILD
index 129e226..e71aa0d 100644
--- a/abs/extra/libmikmod/PKGBUILD
+++ b/abs/extra/libmikmod/PKGBUILD
@@ -1,22 +1,43 @@
-# $Id: PKGBUILD 356 2008-04-18 22:56:27Z aaron $
-# Maintainer: arjan <arjan@archlinux.org>
+# $Id: PKGBUILD 149426 2012-02-07 16:55:08Z heftig $
+# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
+# Contributor: Allan McRae <allan@archlinux.org>
 # Contributor: Tom Newsom <Jeepster@gmx.co.uk>
+
 pkgname=libmikmod
 pkgver=3.1.12
-pkgrel=2
+pkgrel=4
 pkgdesc="A portable sound library"
 license=('GPL' 'LGPL')
 url="http://sourceforge.net/projects/mikmod/"
 arch=('i686' 'x86_64')
 depends=('glibc')
-source=(http://downloads.sourceforge.net/mikmod/${pkgname}-${pkgver}.tar.gz)
-md5sums=('9f3c740298260d5f88981fc0d51f6f16')
 options=('!libtool')
+install=$pkgname.install
+source=(http://downloads.sourceforge.net/mikmod/${pkgname}-${pkgver}.tar.gz
+        libmikmod-3.1.12-64bit-fix.diff
+	libmikmod-3.1.12-exitcrash-fix.diff
+	libmikmod-3.1.12-loopingvolume-fix.diff
+	libmikmod-3.1.12-md_sngchn-fix.diff
+        libmikmod-CVE-2009-0179.patch)
+md5sums=('9f3c740298260d5f88981fc0d51f6f16'
+         'dc7ffd8d6d355e9d6ec671b7f2b2adc7'
+         '03a4f5bfcecddf5f515672d6d477b7f7'
+         'a837fd876cbd2ac27419b802504489db'
+         '076d39de19de36b880ed90297f1ee0d1'
+         'fa91f4bc17164be32bec0ea7a73f2aaa')
 
 build() {
-  cd $startdir/src/$pkgname-$pkgver
-  missing_dir="`pwd`" ./configure --prefix=/usr
+  cd $srcdir/$pkgname-$pkgver
+
+  # patches from sdl_mixer-1.2.11 source
+  patch -Np1 -i $srcdir/libmikmod-3.1.12-64bit-fix.diff
+  patch -Np1 -i $srcdir/libmikmod-3.1.12-exitcrash-fix.diff
+  patch -Np1 -i $srcdir/libmikmod-3.1.12-loopingvolume-fix.diff
+  patch -Np1 -i $srcdir/libmikmod-3.1.12-md_sngchn-fix.diff
+  patch -Np1 -i $srcdir/libmikmod-CVE-2009-0179.patch
+  
+  ./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
   make || return 1
-  make DESTDIR=$startdir/pkg install
+  make DESTDIR=$pkgdir install
 }
 
diff --git a/abs/extra/libmikmod/libmikmod-3.1.12-64bit-fix.diff b/abs/extra/libmikmod/libmikmod-3.1.12-64bit-fix.diff
new file mode 100644
index 0000000..cd78008
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod-3.1.12-64bit-fix.diff
@@ -0,0 +1,47 @@
+Date: Sun, 04 Jul 2004 11:53:23 +0200
+From: Josselin Mouette
+Subject: Re: sdl 64bit problem [PATCH]
+
+Le sam, 03/07/2004 � 18:20 +0200, Hans-Frieder Vogt a �crit :
+> Hi list,
+>
+> I found the problem that lead to the distorted sound in tuxracer on AMD64. It
+> may have also been the cause for the other reported sound problems with SDL.
+> The problem is not in SDL, but in SDL-mixer.
+> There, music files (*.it, and probably others as well) are incorrectly read on
+> all 64 bit architectures but Alpha, due to an incorrect data type definition.
+> The attached patch should solve the problem for all 64 bit architectures on
+> Linux, since at least cpp defines _LP64 and __LP64__ for them.
+> _LP64 indicates that long ints and pointers are 64 bits, but integers are 32
+> bits.
+> I am not sure whether the usage of _LP64 is also standard for the commercial
+> compilers, and for other Unixes, but at least Solaris 9 defines _LP64 in the
+> 64 bit environment as well.
+>
+> Josselin,
+> could you include this patch into your next debian packages?
+
+diff -ru libmikmod-3.1.12.orig/include/mikmod.h.in libmikmod-3.1.12/include/mikmod.h.in
+--- libmikmod-3.1.12.orig/include/mikmod.h.in	2007-12-15 01:24:19.000000000 -0800
++++ libmikmod-3.1.12/include/mikmod.h.in	2009-10-05 00:18:56.000000000 -0700
+@@ -85,7 +85,7 @@
+ 
+ @DOES_NOT_HAVE_SIGNED@
+ 
+-#if defined(__arch64__) || defined(__alpha) || defined(__x86_64)
++#if defined(__arch64__) || defined(__alpha) || defined(__x86_64) || defined(_LP64)
+ /* 64 bit architectures */
+ 
+ typedef signed char     SBYTE;      /* 1 byte, signed */
+diff -ru libmikmod-3.1.12.orig/include/mikmod_internals.h libmikmod-3.1.12/include/mikmod_internals.h
+--- libmikmod-3.1.12.orig/include/mikmod_internals.h	2007-12-15 04:24:51.000000000 -0800
++++ libmikmod-3.1.12/include/mikmod_internals.h	2009-10-05 00:19:15.000000000 -0700
+@@ -50,7 +50,7 @@
+ /*========== More type definitions */
+ 
+ /* SLONGLONG: 64bit, signed */
+-#if defined (__arch64__) || defined(__alpha)
++#if defined(__arch64__) || defined(__alpha) || defined(__x86_64) || defined(_LP64)
+ typedef long		SLONGLONG;
+ #define NATIVE_64BIT_INT
+ #elif defined(__WATCOMC__)
diff --git a/abs/extra/libmikmod/libmikmod-3.1.12-exitcrash-fix.diff b/abs/extra/libmikmod/libmikmod-3.1.12-exitcrash-fix.diff
new file mode 100644
index 0000000..fe62892
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod-3.1.12-exitcrash-fix.diff
@@ -0,0 +1,21 @@
+Date: 15 Apr 2002 11:01:19 +0200
+From: Guillaume Cottenceau <gc@mandrakesoft.com>
+
+Unfortunately, I should have double checked that the following
+fix (authored by Dave Goehrig <dave@cthulhu-burger.org>, not me),
+was really in the CVS... it's not, as of stable 1.2.3 at least.
+Please include it, it fixes a segfault on exiting a program which
+disabled MOD music during its execution.
+
+diff -ru libmikmod-3.1.12.orig/playercode/virtch_common.c libmikmod-3.1.12/playercode/virtch_common.c
+--- libmikmod-3.1.12.orig/playercode/virtch_common.c	2007-12-15 01:26:53.000000000 -0800
++++ libmikmod-3.1.12/playercode/virtch_common.c	2009-10-05 00:37:12.000000000 -0700
+@@ -347,7 +347,7 @@
+ 
+ void VC1_SampleUnload(SWORD handle)
+ {
+-	if (handle<MAXSAMPLEHANDLES) {
++	if (Samples && handle<MAXSAMPLEHANDLES) {
+ 		if (Samples[handle])
+ 			free(Samples[handle]);
+ 		Samples[handle]=NULL;
diff --git a/abs/extra/libmikmod/libmikmod-3.1.12-loopingvolume-fix.diff b/abs/extra/libmikmod/libmikmod-3.1.12-loopingvolume-fix.diff
new file mode 100644
index 0000000..f0ce70e
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod-3.1.12-loopingvolume-fix.diff
@@ -0,0 +1,15 @@
+Yi-Huang Han - Wed Oct 24 21:55:47 PDT 2001
+ * Fixed MOD music volume when looping
+
+diff -ru libmikmod-3.1.12.orig/playercode/mplayer.c libmikmod-3.1.12/playercode/mplayer.c
+--- libmikmod-3.1.12.orig/playercode/mplayer.c	2009-10-05 00:19:59.000000000 -0700
++++ libmikmod-3.1.12/playercode/mplayer.c	2009-10-05 00:44:35.000000000 -0700
+@@ -3019,7 +3019,7 @@
+ {
+ 	MUTEX_LOCK(vars);
+ 	if (pf)
+-		pf->volume=(volume<0)?0:(volume>128)?128:volume;
++		pf->volume=pf->initvolume=(volume<0)?0:(volume>128)?128:volume;
+ 	MUTEX_UNLOCK(vars);
+ }
+ 
diff --git a/abs/extra/libmikmod/libmikmod-3.1.12-md_sngchn-fix.diff b/abs/extra/libmikmod/libmikmod-3.1.12-md_sngchn-fix.diff
new file mode 100644
index 0000000..45cc355
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod-3.1.12-md_sngchn-fix.diff
@@ -0,0 +1,112 @@
+This patch fixes "buffer overflow due to md_numchn - ID: 1630158"
+
+diff -ru libmikmod-3.1.12.orig/playercode/mplayer.c libmikmod-3.1.12/playercode/mplayer.c
+--- libmikmod-3.1.12.orig/playercode/mplayer.c	2007-12-15 01:26:28.000000000 -0800
++++ libmikmod-3.1.12/playercode/mplayer.c	2009-10-04 23:48:36.000000000 -0700
+@@ -52,6 +52,8 @@
+    will wait */
+ /*static*/ MODULE *pf = NULL;
+ 
++#define NUMVOICES(mod)	(md_sngchn < (mod)->numvoices ? md_sngchn : (mod)->numvoices)
++
+ #define	HIGH_OCTAVE		2	/* number of above-range octaves */
+ 
+ static	UWORD oldperiods[OCTAVE*2]={
+@@ -248,14 +250,14 @@
+ 	MP_VOICE *a;
+ 	ULONG t,k,tvol,pp;
+ 
+-	for (t=0;t<md_sngchn;t++)
++	for (t=0;t<NUMVOICES(mod);t++)
+ 		if (((mod->voice[t].main.kick==KICK_ABSENT)||
+ 			 (mod->voice[t].main.kick==KICK_ENV))&&
+ 		   Voice_Stopped_internal(t))
+ 			return t;
+ 
+ 	tvol=0xffffffUL;t=-1;a=mod->voice;
+-	for (k=0;k<md_sngchn;k++,a++) {
++	for (k=0;k<NUMVOICES(mod);k++,a++) {
+ 		/* allow us to take over a nonexisting sample */
+ 		if (!a->main.s)
+ 			return k;
+@@ -2249,12 +2251,12 @@
+ 
+ 	switch (dat) {
+ 	case 0x0: /* past note cut */
+-		for (t=0;t<md_sngchn;t++)
++		for (t=0;t<NUMVOICES(mod);t++)
+ 			if (mod->voice[t].master==a)
+ 				mod->voice[t].main.fadevol=0;
+ 		break;
+ 	case 0x1: /* past note off */
+-		for (t=0;t<md_sngchn;t++)
++		for (t=0;t<NUMVOICES(mod);t++)
+ 			if (mod->voice[t].master==a) {
+ 				mod->voice[t].main.keyoff|=KEY_OFF;
+ 				if ((!(mod->voice[t].venv.flg & EF_ON))||
+@@ -2263,7 +2265,7 @@
+ 			}
+ 		break;
+ 	case 0x2: /* past note fade */
+-		for (t=0;t<md_sngchn;t++)
++		for (t=0;t<NUMVOICES(mod);t++)
+ 			if (mod->voice[t].master==a)
+ 				mod->voice[t].main.keyoff|=KEY_FADE;
+ 		break;
+@@ -2318,7 +2320,7 @@
+ 	SAMPLE *s;
+ 
+ 	mod->totalchn=mod->realchn=0;
+-	for (channel=0;channel<md_sngchn;channel++) {
++	for (channel=0;channel<NUMVOICES(mod);channel++) {
+ 		aout=&mod->voice[channel];
+ 		i=aout->main.i;
+ 		s=aout->main.s;
+@@ -2736,7 +2738,7 @@
+ 			if (a->dct!=DCT_OFF) {
+ 				int t;
+ 
+-				for (t=0;t<md_sngchn;t++)
++				for (t=0;t<NUMVOICES(mod);t++)
+ 					if ((!Voice_Stopped_internal(t))&&
+ 					   (mod->voice[t].masterchn==channel)&&
+ 					   (a->main.sample==mod->voice[t].main.sample)) {
+@@ -2978,6 +2980,11 @@
+ 	if (!(mod->voice=(MP_VOICE*)_mm_calloc(md_sngchn,sizeof(MP_VOICE))))
+ 		return 1;
+ 
++	/* mod->numvoices was used during loading to clamp md_sngchn.
++	   After loading it's used to remember how big mod->voice is.
++	*/
++	mod->numvoices = md_sngchn;
++
+ 	Player_Init_internal(mod);
+ 	return 0;
+ }
+@@ -3086,7 +3093,7 @@
+ 		pf->patbrk=0;
+ 		pf->vbtick=pf->sngspd;
+ 
+-		for (t=0;t<md_sngchn;t++) {
++		for (t=0;t<NUMVOICES(pf);t++) {
+ 			Voice_Stop_internal(t);
+ 			pf->voice[t].main.i=NULL;
+ 			pf->voice[t].main.s=NULL;
+@@ -3111,7 +3118,7 @@
+ 		pf->patbrk=0;
+ 		pf->vbtick=pf->sngspd;
+ 
+-		for (t=0;t<md_sngchn;t++) {
++		for (t=0;t<NUMVOICES(pf);t++) {
+ 			Voice_Stop_internal(t);
+ 			pf->voice[t].main.i=NULL;
+ 			pf->voice[t].main.s=NULL;
+@@ -3138,7 +3145,7 @@
+ 		pf->sngpos=pos;
+ 		pf->vbtick=pf->sngspd;
+ 
+-		for (t=0;t<md_sngchn;t++) {
++		for (t=0;t<NUMVOICES(pf);t++) {
+ 			Voice_Stop_internal(t);
+ 			pf->voice[t].main.i=NULL;
+ 			pf->voice[t].main.s=NULL;
diff --git a/abs/extra/libmikmod/libmikmod-CVE-2009-0179.patch b/abs/extra/libmikmod/libmikmod-CVE-2009-0179.patch
new file mode 100644
index 0000000..0c47e65
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod-CVE-2009-0179.patch
@@ -0,0 +1,33 @@
+diff -ur libmikmod-3.1.11.orig/loaders/load_xm.c libmikmod-3.1.11/loaders/load_xm.c
+--- libmikmod-3.1.11.orig/loaders/load_xm.c	2004-01-21 18:43:53.000000000 +0100
++++ libmikmod-3.1.11/loaders/load_xm.c	2008-04-16 04:30:45.000000000 +0200
+@@ -622,7 +622,8 @@
+ 				/* read the remainder of the header */
+ 				for(u=headend-_mm_ftell(modreader);u;u--) _mm_read_UBYTE(modreader);
+ 
+-				if(_mm_eof(modreader)) {
++				/* last instrument is at the end of file in version 0x0104 */
++				if(_mm_eof(modreader) && (mh->version<0x0104 || t<of.numins-1)) {
+ 					free(nextwav);free(wh);
+ 					nextwav=NULL;wh=NULL;
+ 					_mm_errno = MMERR_LOADING_SAMPLEINFO;
+diff -ur libmikmod-3.1.11.orig/playercode/mloader.c libmikmod-3.1.11/playercode/mloader.c
+--- libmikmod-3.1.11.orig/playercode/mloader.c	2004-01-21 18:43:53.000000000 +0100
++++ libmikmod-3.1.11/playercode/mloader.c	2008-04-16 04:30:45.000000000 +0200
+@@ -450,10 +450,12 @@
+ 	if (!l->Init || l->Init()) {
+ 		_mm_rewind(modreader);
+ 		ok = l->Load(curious);
+-		/* propagate inflags=flags for in-module samples */
+-		for (t = 0; t < of.numsmp; t++)
+-			if (of.samples[t].inflags == 0)
+-				of.samples[t].inflags = of.samples[t].flags;
++		if (ok) {
++			/* propagate inflags=flags for in-module samples */
++			for (t = 0; t < of.numsmp; t++)
++				if (of.samples[t].inflags == 0)
++					of.samples[t].inflags = of.samples[t].flags;
++		}
+ 	} else
+ 		ok = 0;
+ 
diff --git a/abs/extra/libmikmod/libmikmod.install b/abs/extra/libmikmod/libmikmod.install
new file mode 100644
index 0000000..7f80054
--- /dev/null
+++ b/abs/extra/libmikmod/libmikmod.install
@@ -0,0 +1,18 @@
+infodir=/usr/share/info
+filelist=(mikmod.info)
+
+post_install() {
+  for file in ${filelist[@]}; do
+    install-info $infodir/$file.gz $infodir/dir 2> /dev/null
+  done
+}
+
+post_upgrade() {
+  post_install $1
+}
+
+pre_remove() {
+  for file in ${filelist[@]}; do
+    install-info --delete $infodir/$file $infodir/dir 2> /dev/null
+  done
+}
-- 
cgit v0.12

