From owner-freebsd-ports Thu Sep 19 16:30:12 2002 Delivered-To: freebsd-ports@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3492137B401 for ; Thu, 19 Sep 2002 16:30:08 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8342643E6E for ; Thu, 19 Sep 2002 16:30:07 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g8JNU3Co008476 for ; Thu, 19 Sep 2002 16:30:03 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g8JNU3ce008475; Thu, 19 Sep 2002 16:30:03 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0D5C537B401 for ; Thu, 19 Sep 2002 16:22:26 -0700 (PDT) Received: from alcanet.com.au (mail2.alcanet.com.au [203.62.196.17]) by mx1.FreeBSD.org (Postfix) with ESMTP id CC62843E65 for ; Thu, 19 Sep 2002 16:22:24 -0700 (PDT) (envelope-from jeremyp@gsmx07.alcatel.com.au) Received: from sydsmtp01.alcatel.com.au (IDENT:root@localhost.localdomain [127.0.0.1]) by alcanet.com.au (8.12.4/8.12.4/Alcanet1.3) with ESMTP id g8JNMHuC032375; Fri, 20 Sep 2002 09:22:22 +1000 Received: from gsmx07.alcatel.com.au ([139.188.20.247]) by sydsmtp01.alcatel.com.au (Lotus Domino Release 5.0.11) with ESMTP id 2002092009222045:3606 ; Fri, 20 Sep 2002 09:22:20 +1000 Received: from gsmx07.alcatel.com.au (localhost [127.0.0.1]) by gsmx07.alcatel.com.au (8.12.5/8.12.5) with ESMTP id g8JNMK2t008451; Fri, 20 Sep 2002 09:22:20 +1000 (EST) (envelope-from jeremyp@gsmx07.alcatel.com.au) Received: (from jeremyp@localhost) by gsmx07.alcatel.com.au (8.12.5/8.12.5/Submit) id g8JNMKd7008450; Fri, 20 Sep 2002 09:22:20 +1000 (EST) (envelope-from jeremyp) Message-Id: <200209192322.g8JNMKd7008450@gsmx07.alcatel.com.au> Date: Fri, 20 Sep 2002 09:22:20 +1000 (EST) From: Peter Jeremy To: FreeBSD-gnats-submit@FreeBSD.org, murbani@libero.it X-Send-Pr-Version: 3.113 Subject: ports/42975: audio/dagrab generates corrupt mono .WAV files Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 42975 >Category: ports >Synopsis: audio/dagrab generates corrupt mono .WAV files >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Sep 19 16:30:03 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Peter Jeremy >Release: FreeBSD 4.7-PRERELEASE i386 >Organization: Alcatel Australia Limited >Environment: System: FreeBSD server.c18609.belrs1.nsw.optusnet.com.au 4.7-PRERELEASE FreeBSD 4.7-PRERELEASE #4: Sat Sep 14 15:07:16 EST 2002 root@server.c18609.belrs1.nsw.optusnet.com.au:/usr/obj/usr/src/sys/server i386 dagrab-0.3.5 >Description: When generating mono .WAV files from a CD, dagrab generates an incorrect RIFF header and the last (partial) block is saved in stereo rather than mono. Also no error checking is performed on writes in mono mode. The problem in the header is that the total chunk size (Rlen) is not adjusted for mono data and always contains the size assuming stereo data. For the last (partial) block, there is no test whether the data is being saved as mono or stereo - the block is always written in stereo mode. >How-To-Repeat: Grab a track in mono mode and use a WAV file analyser (eg sndfile_info which is part of libsndfile) to validate the structure. >Fix: The following patch is relative to dagrab.c after the FreeBSD ports patch. The patches don't clash but the line numbers may be different. --- dagrab.c.old Thu Sep 19 18:27:00 2002 +++ dagrab.c Thu Sep 19 18:14:46 2002 @@ -206,16 +206,20 @@ struct Wavefile cd_newave(unsigned size) { - struct Wavefile dummy={{'R','I','F','F'},0x24+size,{'W','A','V','E'}, - {'f','m','t',' '},0x10,1,2,44100,4*44100,4,16, - {'d','a','t','a'},size }; - /*dummy.Dlen=size; - dummy.Rlen=0x24+size;*/ - dummy.sample_rate = opt_srate; - dummy.channel = 2 - opt_mono; - dummy.byte_rate = opt_srate << dummy.channel; - dummy.align = dummy.channel * dummy.sample >> 3; - dummy.Dlen >>= opt_mono; + struct Wavefile dummy={{'R','I','F','F'}, /* Rid */ + 0x24 + (size >> opt_mono), /* Rlen */ + {'W','A','V','E'}, /* Wid */ + {'f','m','t',' '}, /* Fid */ + 0x10, /* Flen */ + 1, /* tag */ + 2 - opt_mono, /* channel */ + opt_srate, /* sample_rate */ + opt_srate << (2 - opt_mono), /* byte_rate */ + 16 * (2 - opt_mono) >> 3, /* align */ + 16, /* sample */ + {'d','a','t','a'}, /* Did */ + size >> opt_mono /* Dlen */ + }; return dummy; } @@ -796,6 +800,7 @@ struct Wavefile header; int fd,bytes,i,n,q,space; int bcount, sc, missing, speed = 0, ldp, now; + ssize_t wlen; if(tnmin || tn>tl->max) return (-1); space = ((tl->starts[tn-tl->min+1]-tl->starts[tn-tl->min]) * @@ -879,8 +884,10 @@ d = p1[c]; buf3[c] = ((short)(d&65535) + (short)(d>>16)) >> 1; } - write(fd,buf3,n>>1); - } else if(write(fd,p1,n)==-1){ + wlen = write(fd,buf3,n>>1); + } else + wlen = write(fd,p1,n); + if (wlen == -1){ fprintf(stderr,"%s: error writing wave file %s: %s\n", progname,nam,strerror(errno)); exit(1); @@ -896,7 +903,17 @@ /* dump last bytes */ if (bytes<(tl->starts[tn+1]-tl->starts[tn])*CD_FRAMESIZE_RAW){ n=(tl->starts[tn+1]-tl->starts[tn])*CD_FRAMESIZE_RAW-bytes; - if(write(fd,p1,n)==-1){ + if(opt_mono) { + register int c, d; + for(c = 0; c < (n>>2); c++) { + d = p1[c]; + buf3[c] = ((short)(d&65535) + (short)(d>>16)) >> 1; + } + wlen = write(fd,buf3,n>>1); + } else + wlen = write(fd,p1,n); + + if(wlen==-1){ fprintf(stderr,"%s: error writing wave file %s: %s\n",progname,nam,strerror(errno)); exit(1); }; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message