13531feb863db3591e2c7e61cf45289d3770bc7c
braney
  Mon Oct 31 11:49:46 2022 -0700
for bigWig and bigBed build utilities, check to make sure the file isn't
a pipe

diff --git src/utils/bedToBigBed/bedToBigBed.c src/utils/bedToBigBed/bedToBigBed.c
index 967e596..ad31ff1 100644
--- src/utils/bedToBigBed/bedToBigBed.c
+++ src/utils/bedToBigBed/bedToBigBed.c
@@ -7,30 +7,31 @@
 #include "hash.h"
 #include "options.h"
 #include "dystring.h"
 #include "obscure.h"
 #include "asParse.h"
 #include "basicBed.h"
 #include "memalloc.h"
 #include "sig.h"
 #include "rangeTree.h"
 #include "zlibFace.h"
 #include "sqlNum.h"
 #include "bPlusTree.h"
 #include "bigBed.h"
 #include "bbiAlias.h"
 #include "twoBit.h"
+#include "portable.h"
 
 char *version = "2.9";   // when changing, change in bedToBigBed, bedGraphToBigWig, and wigToBigWig
 /* Version history from 2.6 on at least -
  *   2.9 - ability to specify chromAlias bigBed as chromSizes file
  *   2.8 - Various changes where developer didn't increment version id
  *   2.7 - Added check for duplicate field names in asParse.c
  *   2.6 - Made it not crash on empty input.  
  *   */
 
 /* Things set directly or indirectly by command lne in main() routine. */
 int blockSize = 256;
 int itemsPerSlot = 512;
 char *extraIndex = NULL;
 int bedN = 0;   /* number of standard bed fields */
 int bedP = 0;   /* number of bed plus fields */
@@ -852,30 +853,35 @@
 blockSize = optionInt("blockSize", blockSize);
 itemsPerSlot = optionInt("itemsPerSlot", itemsPerSlot);
 asFile = optionVal("as", asFile);
 doCompress = !optionExists("unc");
 sizesIs2Bit = optionExists("sizesIs2Bit");
 sizesIsChromAliasBb = optionExists("sizesIsChromAliasBb") || optionExists("sizesIsBb");
 if (sizesIs2Bit && sizesIsChromAliasBb)
     errAbort("can't specify both -sizesIs2Bit and -sizesIsChromAliasBb");
 extraIndex = optionVal("extraIndex", NULL);
 tabSep = optionExists("tab");
 allow1bpOverlap = optionExists("allow1bpOverlap");
 udcDir = optionVal("udcDir", udcDefaultDir());
 size_t maxAlloc = optionLongLong("maxAlloc", 0);
 if (argc != 4)
     usage();
+
+char *bedFileName = argv[1];
+
+mustBeReadableAndRegularFile(bedFileName);
+
 udcSetDefaultDir(udcDir);
 if (maxAlloc > 0)
     setMaxAlloc(maxAlloc);
 
 if (optionExists("type"))
     {
     // parse type
     char *btype = cloneString(optionVal("type", ""));
     char *plus = strchr(btype, '+');
     if (plus)
 	{
 	*plus++ = 0;
 	if (isdigit(*plus))
 	    bedP = sqlUnsigned(plus);
 	}
@@ -885,31 +891,30 @@
     bedN = sqlUnsigned(btype);
     if (bedN < 3)
 	errAbort("Bed must be 3 or higher, found %d\n", bedN);
     if (bedN > 15)
 	errAbort("Bed must be 15 or lower, found %d\n", bedN);
     }
 else
     {
     if (asText)
 	errAbort("If you specify the .as file, you must specify the -type as well so that\n"
 	         "the number of standard BED columns is known.");
     }
 
 /* If the haven't set bedN and bedP from the type var in the command line, then we sniff it
  * out from file. */
-char *bedFileName = argv[1];
 if (bedN == 0)
     {
     /* Just read in single line and count fields. */
     struct lineFile *lf = lineFileOpen(bedFileName, TRUE);
     char *line;
     if (!lineFileNextReal(lf, &line))
         errAbort("%s is empty", lf->fileName);
     int fieldCount;
     if (tabSep)
 	fieldCount = chopByChar(line, '\t', NULL, 0); // Do not use chopString, see GOTCHA
     else
 	fieldCount = chopByWhite(line, NULL, 0);
     if (fieldCount > 256)
         errAbort("Too many columns in %s, you sure it's a bed file?", lf->fileName);
     lineFileClose(&lf);