Skip to content

fix: parse the mime metadata when do get/head object#2106

Merged
harshavardhana merged 4 commits intominio:masterfrom
jiuker:fix-parse-the-mime-metadata-when-do-get/head-object
Jun 3, 2025
Merged

fix: parse the mime metadata when do get/head object#2106
harshavardhana merged 4 commits intominio:masterfrom
jiuker:fix-parse-the-mime-metadata-when-do-get/head-object

Conversation

@jiuker
Copy link
Copy Markdown
Contributor

@jiuker jiuker commented May 13, 2025

fix: parse the mime metadata when do get/head object
will work with minio/minio#21282

fix: parse the mime metadata when do get/head object
@jiuker jiuker requested review from Copilot, harshavardhana and klauspost and removed request for klauspost May 13, 2025 05:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances metadata handling by decoding MIME-encoded metadata values for GET/HEAD operations and adds targeted unit tests.

  • Decode Q-/B-encoded values for both X-Minio-Meta- and X-Amz-Meta- headers in extractObjMetadata.
  • Add TestExtractObjMetadata to cover plain, Q-encoded, and B-encoded metadata scenarios.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
utils.go Import mime and extend extractObjMetadata to detect and decode MIME word–encoded metadata.
utils_test.go Add TestExtractObjMetadata with cases for unencoded, Q-encoded, and B-encoded metadata values.
Comments suppressed due to low confidence (1)

utils_test.go:493

  • Consider adding a corresponding test case for the AWS-style X-Amz-Meta- prefix to ensure that the same decoding logic also applies correctly to AWS metadata headers.
"X-Minio-Meta-Test": []string{mime.QEncoding.Encode("UTF-8", "öha, das")},

Comment thread utils.go Outdated
Comment thread utils.go Outdated
Comment thread utils.go Outdated
}
found = true
if len(v) == 1 && (prefix == "X-Amz-Meta-" || prefix == "X-Minio-Meta-") {
i := strings.Index(v[0], "=?")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be other than at the start of the value? Maybe just check prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only metadata have that string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking of i := strings.Index(v[0], "=?") vs if strings.HasPrefix(v[0], "=?") - so it will not be picked up from within the middle of values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// DecodeHeader decodes all encoded-words of the given string. It returns an
// error if and only if [WordDecoder.CharsetReader] of d returns an error.
func (d *WordDecoder) DecodeHeader(header string) (string, error) {
	// If there is no encoded-word, returns before creating a buffer.
	i := strings.Index(header, "=?")
	if i == -1 {
		return header, nil
	}

And I have test the string such as Test=?utf-8?q?=C3=B6?= can be deocded @klauspost

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiuker Is that valid encoding? That is why I am asking.

If it is sent as Test=?utf-8?q?=C3=B6?= the client would expect to get it back like this and should return it as-is. We need to be roundtrip safe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes valid encoding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klauspost Yesh. I think HavePrefix should be better. Could you take a look here.

support mutil val
@jiuker jiuker requested a review from klauspost May 13, 2025 09:13
Comment thread utils.go Outdated
@jiuker jiuker requested a review from harshavardhana May 16, 2025 01:14
simple
prefix
@harshavardhana
Copy link
Copy Markdown
Member

@klauspost PTAL

@harshavardhana harshavardhana merged commit 14d7d61 into minio:master Jun 3, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants