Browse Source

Improve trailer parsing robustness in parseChunkChecksum

- Remove redundant trimTrailingWhitespace call since readChunkLine already trims
- Use bytes.TrimSpace for both key and value to handle whitespace around colon separator
- Follows HTTP header specifications for optional whitespace around separators
- Addresses Gemini Code Assist review feedback
pull/7595/head
Chris Lu 2 days ago
parent
commit
ec325a3514
  1. 9
      weed/s3api/chunked_reader_v4.go

9
weed/s3api/chunked_reader_v4.go

@ -520,15 +520,14 @@ func parseChunkChecksum(b *bufio.Reader) (ChecksumAlgorithm, []byte, error) {
return ChecksumAlgorithmNone, nil, err return ChecksumAlgorithmNone, nil, err
} }
line := trimTrailingWhitespace(bytesRead)
if len(line) == 0 {
if len(bytesRead) == 0 {
break break
} }
parts := bytes.SplitN(line, []byte(":"), 2)
parts := bytes.SplitN(bytesRead, []byte(":"), 2)
if len(parts) == 2 { if len(parts) == 2 {
key := string(parts[0])
value := trimTrailingWhitespace(parts[1])
key := string(bytes.TrimSpace(parts[0]))
value := bytes.TrimSpace(parts[1])
if alg, err := extractChecksumAlgorithm(key); err == nil { if alg, err := extractChecksumAlgorithm(key); err == nil {
if checksumAlgorithm != ChecksumAlgorithmNone { if checksumAlgorithm != ChecksumAlgorithmNone {
glog.V(3).Infof("multiple checksum headers found in trailer, using last: %s", key) glog.V(3).Infof("multiple checksum headers found in trailer, using last: %s", key)

Loading…
Cancel
Save