-
Notifications
You must be signed in to change notification settings - Fork 175
Closed
Description
I use mimetype extensively in my internal code, but I recently discovered a weird bug where the data returned to the user was corrupted.
We first read 4K bytes of data to mimetype to detect the file type, then use io.MultiReader to merge the 4K data with the remaining reader and return it to the user. I found that the 4K bytes of data content was modified, and finally located the CSV detection parser.
func (r *Parser) readLine() []byte {
line := r.s.ReadSlice('\n')
n := len(line)
if n > 0 && line[n-1] == '\r' {
return line[:n-1] // drop \r at end of line
}
// Normalize \r\n to \n on all input lines.
if n := len(line); n >= 2 && line[n-2] == '\r' && line[n-1] == '\n' {
line[n-2] = '\n'
return line[:n-1]
}
return line
}
Metadata
Metadata
Assignees
Labels
No labels