Merge pull request #1006 from github/fix-scanner-panic

skip scanner lines that are too short
This commit is contained in:
risk danger olson 2016-02-22 11:25:09 -07:00
commit d69ccc1c7a

@ -370,20 +370,29 @@ func catFileBatchCheck(revs chan string) (chan string, error) {
scanner := bufio.NewScanner(cmd.Stdout)
for scanner.Scan() {
line := scanner.Text()
lineLen := len(line)
// Format is:
// <sha1> <type> <size>
// type is at a fixed spot, if we see that it's "blob", we can avoid
// splitting the line just to get the size.
if line[41:45] == "blob" {
size, err := strconv.Atoi(line[46:len(line)])
if lineLen < 46 {
continue
}
if line[41:45] != "blob" {
continue
}
size, err := strconv.Atoi(line[46:lineLen])
if err != nil {
continue
}
if size < blobSizeCutoff {
smallRevs <- line[0:40]
}
}
}
cmd.Wait()
close(smallRevs)