From patchwork Tue May 15 20:21:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 10401961 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4442C601C8 for ; Tue, 15 May 2018 20:22:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 315A428536 for ; Tue, 15 May 2018 20:22:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 257A128541; Tue, 15 May 2018 20:22:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BC2D28574 for ; Tue, 15 May 2018 20:21:54 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9B956266DF0; Tue, 15 May 2018 22:21:51 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5CB21266F44; Tue, 15 May 2018 22:21:48 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 81F37266C1C for ; Tue, 15 May 2018 22:21:44 +0200 (CEST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 37F07AC93; Tue, 15 May 2018 20:21:43 +0000 (UTC) Date: Tue, 15 May 2018 22:21:42 +0200 Message-ID: From: Takashi Iwai To: jay@systech.com In-Reply-To: <95e41d1c-1143-320e-0c95-d8d67bd485a1@systech.com> References: <8c51a51a-cfa0-e1a7-0682-8f3c13ddc2a7@systech.com> <399d9244-ae31-84c0-d587-bc62707a873f@systech.com> <95e41d1c-1143-320e-0c95-d8d67bd485a1@systech.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] Aplay Fails When Reading From stdin X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 07 May 2018 17:37:44 +0200, Jay Foster wrote: > > > > On 5/4/2018 11:51 PM, Takashi Iwai wrote: > > On Fri, 04 May 2018 21:57:35 +0200, > > Jay Foster wrote: > >> > >> > >> On 5/4/2018 12:47 PM, Takashi Iwai wrote: > >>> On Fri, 04 May 2018 19:51:05 +0200, > >>> Jay Foster wrote: > >>>> I recently updated may alsa from 1.1.4.1 to 1.1.6. I now noticed that > >>>> aplay does not work properly (the same as 1.1.4.1) when reading the > >>>> sound file data from stdin. This might have something to do with the > >>>> recent change with reading the sound file header. > >>>> > >>>> With the previous version of aplay, aplay would report: > >>>> > >>>> Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono > >>>> > >>>> With 1.1.6, aplay reports: > >>>> > >>>> Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono > >>>> > >>>> This results in static/noise output. If I explicitly add the '-f > >>>> S16_LE -r 22050' options to aplay, then it does play correctly. > >>>> > >>>> Is this a known bug and is there a fix? > >>> It works fine on my system. > >>> > >>> % aplay test.wav > >>> Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo > >>> > >>> % aplay < ~/test/test.wav > >>> Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo > >>> > >>> % aplay --version > >>> aplay: version 1.1.6 by Jaroslav Kysela > >>> > >>> > >>> Takashi > >>> > >>> > >> Well, it does not work for me: > >> > >> cat bird-calls.wav | /usr/bin/aplay -Dplughw:0 -- > >> Playing raw data 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono > >> ^CAborted by signal Interrupt... > >> aplay: pcm_write:2051: write error: Interrupted system call > >> > >> aplay -Dplughw:0 bird-calls.wav > >> Playing WAVE 'bird-calls.wav' : Signed 16 bit Little Endian, Rate > >> 44100 Hz, Stereo > >> > >> Looks like aplay may now have problems reading from stdin if stdin is > >> a pipe. > > OK, now I see it. It's in the safety check of file stat. > > The fix patch is below. > > > Thanks.  That works. Actually the fix below would be much simpler and better. I'm going to apply it. Takashi -- 8< -- From: Takashi Iwai Subject: [PATCH] aplay: Fix invalid file size check for non-regular files aplay tries to check the file size via fstat() at parsing the format headers and avoids parsing when the size is shorter than the given size. This works fine for regular files, but when a special file like pipe is passed, it fails, eventually leading to the fallback mode wrongly. A proper fix is to do this sanity check only for a regular file. Reported-by: Jay Foster Signed-off-by: Takashi Iwai --- aplay/aplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index bbd7fffa04fc..63ec9efbebc1 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -2821,7 +2821,8 @@ static int read_header(int *loaded, int header_size) /* don't be adventurous, get out if file size is smaller than * requested header size */ - if (buf.st_size < header_size) + if ((buf.st_mode & S_IFMT) == S_IFREG && + buf.st_size < header_size) return -1; if (*loaded < header_size) {