Subject: pkg/8610: pkgsrc/audio/lame exits normally on input file read error
To: None <>
From: Sean Doran <>
List: netbsd-bugs
Date: 10/11/1999 15:54:52
>Number:         8610
>Category:       pkg
>Synopsis:       lame has bad read error handling in read_samples() [getaudio.c:431]
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager (NetBSD software packages system bug manager)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 11 15:03:00 1999
>Originator:     Sean Doran
>Release:        19991009
System: NetBSD 1.4K NetBSD 1.4K (SMDHOME) #0: Sat Oct 9 16:37:47 CEST 1999 i386
	pkgsrc supped 9 Oct 1999

	pkg/lame (and pkg/lame-gui) suffers from poor read error
	handling in read_samples() [getaudio.c:431]

	in particular, when fread(3) returns 0, there is no attempt
        to determine why; the code just falls through a commented-out
	printf (!)

	moreover, a short fread(3) [including a 0 "short read"]
        returns upwards towards a comment in makeframe() [main.c:11]

  /* even if iread=0, get_audio hit EOF and returned Buffer=all 0's.  call
   * makeframe() one last time to flush all buffers */

	gross!  we might not have hit EOF!  we should NOT NOT NOT exit

	lame_lastreadframe() [musicin.c:1315] is funny.

	static int eof;
	if(!eof) {
		if( (###result of fread from read_samples ###) == 0 ) {
		/*this is the last frame*/
	} else {
		/*do cleanup*/


	1 Use pkgsrc/audio/cdd to dump a bunch of PCM files onto a partition
	  on a flaking-out disk (unrecoverable reads)

	2 run a simple script like this one in pkgsrc/plan9/rc dialect:

		lameopts=(--nohist -m f -p -h -v -V 5 -b 32 -x -r)
		for (a in $*) {
			b=`{echo $a | sed 's,.cda$,.mp3,'}
			echo $^a '->' $^b
			/usr/pkg/bin/lame $lameopts $^a $^b && /bin/rm -f $^a

	3 become REALLY annoyed when you discover that lame exits normally
	  when a read error happens


	$ /bin/rc
	: crasse ; lameopts=(--nohist -m f -p -h -v -V 5 -b 32 -x -r)
	: crasse ; cat /etc/rc.local | lame $lameopts - /tmp/x
	: crasse ; echo $status
	0 0
	: crasse ; lame $lameopts /tmp/doesnotexist /tmp/x
	LAME version 3.31 ( 
	GPSYCHO: GPL psycho-acoustic model version 0.73. 
	Could not find "/tmp/doesnotexist".
	: crasse ; echo $status
	: crasse ; cat /tmp/doesnotexist | lame $lameopts - /tmp/xxx
	cat: /tmp/doesnotexist: No such file or directory
	LAME version 3.31 ( 
	GPSYCHO: GPL psycho-acoustic model version 0.73. 
	Assuming raw pcm input file : Forcing byte-swapping
	Encoding stdin to /tmp/xxx
	Encoding as 44.1kHz VBR(q=5) j-stereo MPEG1 LayerIII file
	: crasse ; echo $status
	1 0

	At least cat(1) exits with nonzero status...  ^*&@#$