24acb82692d011bbbfd37e49fa75bdaf3e59e2af
galt
  Wed Feb 3 10:24:06 2016 -0800
added code to verify that for BED input data the chrom exists in the database and that chromEnd is not > chrom size.

diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index 7513667..1e7eec5 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -4006,30 +4006,43 @@
     else
 	{
 	//warn("got numFields=%d, expectedFieldCount=%d", numFields, expectedFieldCount); // DEBUG REMOVE
 	if (numFields != expectedFieldCount)
 	    errAbort("Multi-Region BED was detected to have %d columns. But this row has %d columns. "
 	    "All rows except comment lines should have the same number of columns", numFields, expectedFieldCount);
 	}
 
     //warn("got about to call load and validate bed"); // DEBUG REMOVE
 
     AllocVar(bed);
     // All fields are standard BED fields, no bedplus fields supported at this time.
     // note: this function does not validate chrom name or end beyond chrom size
     loadAndValidateBed(row, numFields, numFields+0, lf, bed, NULL, TRUE);
     bed->chrom=cloneString(bed->chrom);  // loadAndValidateBed does not do it for speed. but bedFree needs it.
+
+    struct chromInfo *ci = hGetChromInfo(database, bed->chrom);
+    if (ci == NULL)
+	{
+        warn("Couldn't find chromosome/scaffold %s in database", bed->chrom);
+	return FALSE;
+	}
+    if (bed->chromEnd > ci->size)
+	{
+        warn("BED chromEnd %u > size %u for chromosome/scaffold %s", bed->chromEnd, ci->size, bed->chrom);
+	return FALSE;
+	}
+
     slAddHead(&bedList, bed);
 
     //warn("got after load and validate bed"); // DEBUG REMOVE
 
     struct virtRegion *v;
     if (numFields < 12)
 	{
 	AllocVar(v);
 	v->chrom = cloneString(bed->chrom);
 	v->start = bed->chromStart;
 	v->end   = bed->chromEnd;
 	slAddHead(&virtRegionList, v);
 	//warn("got BED region %s %d %d", v->chrom, v->start, v->end); // DEBUG REMOVE
 	}
     else