Blob Blame History Raw
From da4d5bd53a1a57d1b39318b83d3280fbcd78e9f6 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 15 May 2018 22:17:01 +0200
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 <jay@systech.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 aplay/aplay.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/aplay/aplay.c b/aplay/aplay.c
index bbd7fff..63ec9ef 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) {
-- 
2.13.6