Skip to content

Commit b4976bb

Browse files
authored
Fix bounds check in import scanner (#8494)
* Fix bounds check in import scanner * Add test * zach commments
1 parent 6e04347 commit b4976bb

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

go/cmd/dolt/commands/sql_statement_scanner.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,20 @@ func (s *streamScanner) Scan() bool {
9696
}
9797

9898
// discard leading whitespace
99-
for ; unicode.IsSpace(rune(s.buf[s.i])); s.i++ {
100-
if s.buf[s.i] == '\n' {
101-
s.lineNum++
102-
}
99+
for {
103100
if s.i >= s.fill {
104101
if err := s.read(); err != nil {
105102
s.err = err
106103
return false
107104
}
108105
}
106+
if !unicode.IsSpace(rune(s.buf[s.i])) {
107+
break
108+
}
109+
if s.buf[s.i] == '\n' {
110+
s.lineNum++
111+
}
112+
s.i++
109113
}
110114
s.truncate()
111115

go/cmd/dolt/commands/sql_statement_scanner_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ insert into foo values (1,2,3)|`,
187187
},
188188
lineNums: []int{1, 2},
189189
},
190+
{
191+
// https://github.com/dolthub/dolt/issues/8495
192+
input: strings.Repeat(" ", 4096) + `insert into foo values (1,2,3)`,
193+
statements: []string{
194+
"insert into foo values (1,2,3)",
195+
},
196+
lineNums: []int{1, 2},
197+
},
190198
}
191199

192200
for _, tt := range testcases {

0 commit comments

Comments
 (0)