c5225b06da002ec4b1f5cf3946300d5d43f1cb5d
chmalee
  Wed Feb 7 15:43:09 2024 -0800
Check array is not full when reading INFO tags to keep from a file, refs #32973

diff --git src/hg/utils/vcfToBed/vcfToBed.c src/hg/utils/vcfToBed/vcfToBed.c
index 08e4705..7ad6f63 100644
--- src/hg/utils/vcfToBed/vcfToBed.c
+++ src/hg/utils/vcfToBed/vcfToBed.c
@@ -226,31 +226,31 @@
     if (vcff == NULL)
         errAbort("error opening %s\n", vcfFileName);
     vcfTagCount = slCount(vcff->infoDefs);
     // do a batch read and use the reuse pool
     vcfFileMakeReusePool(vcff, 64*1024*1024);
     }
 else
     errAbort("no tabix index for %s\n", vcfFileName);
 
 if (tagsToKeep)
     {
     if (fieldsIsFile)
         {
         struct lineFile *lf = lineFileOpen(tagsToKeep, FALSE);
         char *tag;
-        while (lineFileNextRow(lf, &tag, 1))
+        while ( (keepCount < MAX_BED_EXTRA) && lineFileNextRow(lf, &tag, 1))
             tempKeepFields[keepCount++] = cloneString(tag);
         }
     else
         keepCount = chopCommas(tagsToKeep, tempKeepFields);
     if (keepCount > vcfTagCount)
         verbose(2, "Warning: fewer fields in VCF than -fields specification.");
     keepCount = trimMissingTagsFromFieldList(keepFields, tempKeepFields, keepCount, vcff);
     }
 
 // open output for writing
 char *outBedName = NULL;
 if (endsWith(outPrefix, ".bed"))
     outBedName = cloneString(outPrefix);
 else
     outBedName = catTwoStrings(outPrefix, ".bed");