Fix index out of bounds error.
authorTom Clegg <tom@curii.com>
Wed, 29 Dec 2021 14:33:09 +0000 (09:33 -0500)
committerTom Clegg <tom@curii.com>
Wed, 29 Dec 2021 14:34:12 +0000 (09:34 -0500)
refs #18438

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

slicenumpy.go

index d780eb55c7e59ba84eb19b1e5d06790443e72a21..3af4aa04ef51cbc6a0dbefd5fce8c5863d7d3a00 100644 (file)
@@ -309,9 +309,16 @@ func (cmd *sliceNumpy) RunCommand(prog string, args []string, stdin io.Reader, s
                                        seq[tv.Tag] = variants
                                }
                                for _, cg := range ent.CompactGenomes {
-                                       if matchGenome.MatchString(cg.Name) {
-                                               cgs[cg.Name] = cg
+                                       if !matchGenome.MatchString(cg.Name) {
+                                               continue
+                                       }
+                                       // pad to full slice size
+                                       // to avoid out-of-bounds
+                                       // checks later
+                                       if sliceSize := int(cg.EndTag - cg.StartTag); len(cg.Variants) < sliceSize {
+                                               cg.Variants = append(cg.Variants, make([]tileVariantID, sliceSize-len(cg.Variants))...)
                                        }
+                                       cgs[cg.Name] = cg
                                }
                                return nil
                        })
@@ -340,12 +347,10 @@ func (cmd *sliceNumpy) RunCommand(prog string, args []string, stdin io.Reader, s
 
                                        for _, cg := range cgs {
                                                idx := int(tag-tagstart) * 2
-                                               if idx < len(cg.Variants) {
-                                                       for allele := 0; allele < 2; allele++ {
-                                                               v := cg.Variants[idx+allele]
-                                                               if v > 0 && len(variants[v].Sequence) > 0 {
-                                                                       count[variants[v].Blake2b]++
-                                                               }
+                                               for allele := 0; allele < 2; allele++ {
+                                                       v := cg.Variants[idx+allele]
+                                                       if v > 0 && len(variants[v].Sequence) > 0 {
+                                                               count[variants[v].Blake2b]++
                                                        }
                                                }
                                        }