Skip to content

Index Out of Bounds Panic on array length comparison  #1

@EmmaLouise2018

Description

@EmmaLouise2018

In index.go there is the function hasPrefix()

func (o *IndexDef) hasPrefix(columns []string) bool {
     if len(o.Columns) < len(columns) {
         return false
     }
 
     for i := range o.Columns {
         if o.Columns[i] != columns[i] {
             return false
         }
     }
     return true
 }

This causes an index out of bounds exception if the length of o.Columns is longer than that of columns since we are iterating through o.Columns in the for loop.

This check should be if len(o.Columns) > len(columns) to make sure we are not iterating through the longer array.

After making this change, all the tests continue to pass as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions