30cb0185fefa49d413bdc67d45e11cb4bbf8d5ce chmalee Tue May 19 13:48:17 2020 -0700 Adding check to vcf parsing for number of required headers after user's custom track caused hgCustom to crash, refs #25603 diff --git src/lib/vcf.c src/lib/vcf.c index 2fb4688..b19c904 100644 --- src/lib/vcf.c +++ src/lib/vcf.c @@ -392,51 +392,54 @@ if (! sameString(exp1, words[ix])) { if (exp2 == NULL) vcfFileErr(vcff, "Expected column %d's name in header to be \"%s\" but got \"%s\"", ix+1, exp1, words[ix]); else if (! sameString(exp2, words[ix])) vcfFileErr(vcff, "Expected column %d's name in header to be \"%s\" or \"%s\" " "but got \"%s\"", ix+1, exp1, exp2, words[ix]); } } #define expectColumnName(vcff, exp, words, ix) expectColumnName2(vcff, exp, NULL, words, ix) // There might be a whole lot of genotype columns... #define VCF_MAX_COLUMNS 16 * 1024 +#define VCF_MIN_COLUMNS 8 char *vcfDefaultHeader = "#CHROM POS ID REF ALT QUAL FILTER INFO"; /* Default header if we have none. */ static void parseColumnHeaderRow(struct vcfFile *vcff, char *line) /* Make sure column names are as we expect, and store genotype sample IDs if any are given. */ { char *words[VCF_MAX_COLUMNS]; int wordCount = chopLine(line+1, words); if (wordCount >= VCF_MAX_COLUMNS) vcfFileErr(vcff, "header contains at least %d columns; " "VCF_MAX_COLUMNS may need to be increased in vcf.c!", VCF_MAX_COLUMNS); +if (wordCount < VCF_MIN_COLUMNS) + errAbort("VCF header missing at least one of the required VCF fields"); expectColumnName(vcff, "CHROM", words, 0); expectColumnName(vcff, "POS", words, 1); expectColumnName(vcff, "ID", words, 2); expectColumnName(vcff, "REF", words, 3); expectColumnName(vcff, "ALT", words, 4); expectColumnName2(vcff, "QUAL", "PROB", words, 5); expectColumnName(vcff, "FILTER", words, 6); expectColumnName(vcff, "INFO", words, 7); -if (wordCount > 8) +if (wordCount > VCF_MIN_COLUMNS) { expectColumnName(vcff, "FORMAT", words, 8); if (wordCount < 10) vcfFileErr(vcff, "FORMAT column is given, but no sample IDs for genotype columns...?"); vcff->genotypeCount = (wordCount - 9); vcff->genotypeIds = vcfFileAlloc(vcff, vcff->genotypeCount * sizeof(char *)); int i; for (i = 9; i < wordCount; i++) vcff->genotypeIds[i-9] = vcfFileCloneStr(vcff, words[i]); } } struct vcfFile *vcfFileNew() /* Return a new, empty vcfFile object. */ {