]> git.sesse.net Git - x264/commitdiff
Fix SIGPIPEs caused by is_regular_file checks
authorAnton Mitrofanov <BugMaster@narod.ru>
Fri, 18 Jun 2010 21:44:56 +0000 (01:44 +0400)
committerFiona Glaser <fiona@x264.com>
Wed, 23 Jun 2010 20:22:50 +0000 (13:22 -0700)
Check to see if input file is a pipe without opening it.

common/osdep.h
x264.c

index b1b357c0816b41401a03a7226973c3685532b832..b3a8cd6ca6343476ae728242e5f9700fa2b9a70f 100644 (file)
@@ -290,7 +290,15 @@ static inline uint8_t x264_is_regular_file( FILE *filehandle )
 {
     struct stat file_stat;
     if( fstat( fileno( filehandle ), &file_stat ) )
-        return 0;
+        return -1;
+    return S_ISREG( file_stat.st_mode );
+}
+
+static inline uint8_t x264_is_regular_file_path( const char *filename )
+{
+    struct stat file_stat;
+    if( stat( filename, &file_stat ) )
+        return -1;
     return S_ISREG( file_stat.st_mode );
 }
 
diff --git a/x264.c b/x264.c
index a124083aab4470bae81a2d4b3047d0e31b690899..09bad61c82afef08f8ce5860d43210e0ee26d34d 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -806,6 +806,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
     int b_auto = !strcasecmp( demuxer, "auto" );
     if( !b_regular && b_auto )
         ext = "yuv";
+    b_regular = b_regular && x264_is_regular_file_path( filename );
     if( b_regular )
     {
         FILE *f = fopen( filename, "r" );