Skip to content

Commit

Permalink
Fix bounds check in import scanner (#8494)
Browse files Browse the repository at this point in the history
* Fix bounds check in import scanner

* Add test

* zach commments
  • Loading branch information
max-hoffman authored Oct 25, 2024
1 parent 6e04347 commit b4976bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions go/cmd/dolt/commands/sql_statement_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ func (s *streamScanner) Scan() bool {
}

// discard leading whitespace
for ; unicode.IsSpace(rune(s.buf[s.i])); s.i++ {
if s.buf[s.i] == '\n' {
s.lineNum++
}
for {
if s.i >= s.fill {
if err := s.read(); err != nil {
s.err = err
return false
}
}
if !unicode.IsSpace(rune(s.buf[s.i])) {
break
}
if s.buf[s.i] == '\n' {
s.lineNum++
}
s.i++
}
s.truncate()

Expand Down
8 changes: 8 additions & 0 deletions go/cmd/dolt/commands/sql_statement_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ insert into foo values (1,2,3)|`,
},
lineNums: []int{1, 2},
},
{
// https://github.com/dolthub/dolt/issues/8495
input: strings.Repeat(" ", 4096) + `insert into foo values (1,2,3)`,
statements: []string{
"insert into foo values (1,2,3)",
},
lineNums: []int{1, 2},
},
}

for _, tt := range testcases {
Expand Down

0 comments on commit b4976bb

Please sign in to comment.