[fix] S3Select: Add some missing input validation (#20278)

Prevents server panic when some CSV parameters are empty.
This commit is contained in:
Aditya Manthramurthy 2024-08-20 11:31:45 -07:00 committed by GitHub
parent 85c3db3a93
commit 8a11282522
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 6 deletions

View File

@ -27,8 +27,9 @@ import (
)
const (
none = "none"
use = "use"
none = "none"
use = "use"
ignore = "ignore"
defaultRecordDelimiter = "\n"
defaultFieldDelimiter = ","
@ -92,11 +93,22 @@ func (args *ReaderArgs) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (er
}
switch tagName {
case "FileHeaderInfo":
args.FileHeaderInfo = strings.ToLower(s)
s = strings.ToLower(s)
if len(s) != 0 {
if s != none && s != use && s != ignore {
return errors.New("unsupported FileHeaderInfo")
}
args.FileHeaderInfo = s
}
case "RecordDelimiter":
args.RecordDelimiter = s
if len(s) != 0 {
args.RecordDelimiter = s
}
case "FieldDelimiter":
args.FieldDelimiter = s
if len(s) != 0 {
args.FieldDelimiter = s
}
case "QuoteCharacter":
if utf8.RuneCountInString(s) > 1 {
return fmt.Errorf("unsupported QuoteCharacter '%v'", s)
@ -112,7 +124,9 @@ func (args *ReaderArgs) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (er
return fmt.Errorf("unsupported QuoteEscapeCharacter '%v'", s)
}
case "Comments":
args.CommentCharacter = s
if len(s) != 0 {
args.CommentCharacter = s
}
default:
return errors.New("unrecognized option")
}