Fix array index out of bounds.
authorTom Clegg <tom@tomclegg.ca>
Thu, 12 Aug 2021 03:16:36 +0000 (23:16 -0400)
committerTom Clegg <tom@tomclegg.ca>
Thu, 12 Aug 2021 03:16:36 +0000 (23:16 -0400)
refs #17562

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

export.go

index 7f6d84cef3ea34a9759fac6856dfd4975736c162..f44f6a87243b2e2b157f8c6118515733cdfc9b74 100644 (file)
--- a/export.go
+++ b/export.go
@@ -493,7 +493,13 @@ func eachVariant(bedw io.Writer, taglen int, seqname string, reftiles []tileLibR
                                // This could be either =ref or a
                                // missing/low-quality tile. Figure
                                // out which.
-                               v := cgs[i/2].Variants[int(libref.Tag)*2+i%2]
+                               vidx := int(libref.Tag)*2 + i%2
+                               if vidx >= len(cgs[i/2].Variants) {
+                                       // Missing tile.
+                                       varslice[i].New = "-"
+                                       continue
+                               }
+                               v := cgs[i/2].Variants[vidx]
                                if v < 1 || len(tilelib.TileVariantSequence(tileLibRef{Tag: libref.Tag, Variant: v})) == 0 {
                                        // Missing/low-quality tile.
                                        varslice[i].New = "-" // fasta "gap of indeterminate length"