Skip to content

Commit

Permalink
Fixed ETag parsing at completing the Multipart upload part
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Oct 12, 2023
1 parent e5b15be commit fa21ca2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
11 changes: 4 additions & 7 deletions src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4218,6 +4218,7 @@ bool S3fsCurl::UploadMultipartPostComplete()
if (it == responseHeaders.end()) {
return false;
}
std::string etag = peeloff(it->second);

// check etag(md5);
//
Expand All @@ -4227,11 +4228,11 @@ bool S3fsCurl::UploadMultipartPostComplete()
// https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html
//
if(S3fsCurl::is_content_md5 && sse_type_t::SSE_C != S3fsCurl::GetSseType() && sse_type_t::SSE_KMS != S3fsCurl::GetSseType()){
if(!etag_equals(it->second, partdata.etag)){
if(!etag_equals(etag, partdata.etag)){
return false;
}
}
partdata.petag->etag = it->second;
partdata.petag->etag = etag;
partdata.uploaded = true;

return true;
Expand All @@ -4255,11 +4256,7 @@ bool S3fsCurl::CopyMultipartPostComplete()
{
std::string etag;
partdata.uploaded = simple_parse_xml(bodydata.c_str(), bodydata.size(), "ETag", etag);
if(etag.size() >= 2 && *etag.begin() == '"' && *etag.rbegin() == '"'){
etag.erase(etag.size() - 1);
etag.erase(0, 1);
}
partdata.petag->etag = etag;
partdata.petag->etag = peeloff(etag);

bodydata.clear();
headdata.clear();
Expand Down
12 changes: 2 additions & 10 deletions src/curl_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,9 @@ const char* getCurlDebugHead(curl_infotype type)
//
// compare ETag ignoring quotes and case
//
bool etag_equals(std::string s1, std::string s2)
bool etag_equals(const std::string& s1, const std::string& s2)
{
if(s1.length() > 1 && s1[0] == '\"' && *s1.rbegin() == '\"'){
s1.erase(s1.size() - 1);
s1.erase(0, 1);
}
if(s2.length() > 1 && s2[0] == '\"' && *s2.rbegin() == '\"'){
s2.erase(s2.size() - 1);
s2.erase(0, 1);
}
return 0 == strcasecmp(s1.c_str(), s2.c_str());
return 0 == strcasecmp(peeloff(s1).c_str(), peeloff(s2).c_str());
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/curl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::string url_to_host(const std::string &url);
std::string get_bucket_host();
const char* getCurlDebugHead(curl_infotype type);

bool etag_equals(std::string s1, std::string s2);
bool etag_equals(const std::string& s1, const std::string& s2);

#endif // S3FS_CURL_UTIL_H_

Expand Down
8 changes: 8 additions & 0 deletions src/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ std::string trim(std::string s, const char *t /* = SPACES */)
return trim_left(trim_right(std::move(s), t), t);
}

std::string peeloff(std::string s)
{
if(s.size() < 2 || *s.begin() != '"' || *s.rbegin() != '"'){
return s;
}
return s.substr(1, s.size() - 2);
}

//
// Three url encode functions
//
Expand Down
1 change: 1 addition & 0 deletions src/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ std::string trim_left(std::string s, const char *t = SPACES);
std::string trim_right(std::string s, const char *t = SPACES);
std::string trim(std::string s, const char *t = SPACES);
std::string lower(std::string s);
std::string peeloff(std::string s);

//
// Date string
Expand Down
9 changes: 9 additions & 0 deletions src/test_string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ void test_trim()
ASSERT_EQUALS(std::string("1234"), trim_right("1234 "));
ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234"));
ASSERT_EQUALS(std::string("1234"), trim_right("1234"));

ASSERT_EQUALS(std::string("1234"), peeloff("\"1234\"")); // "1234" -> 1234
ASSERT_EQUALS(std::string("\"1234\""), peeloff("\"\"1234\"\"")); // ""1234"" -> "1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"\"1234\"")); // ""1234" -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("\"1234\"\"")); // "1234"" -> 1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"1234")); // "1234 -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("1234\"")); // 1234" -> 1234"
ASSERT_EQUALS(std::string(" \"1234\""), peeloff(" \"1234\"")); // _"1234" -> _"1234"
ASSERT_EQUALS(std::string("\"1234\" "), peeloff("\"1234\" ")); // "1234"_ -> "1234"_
}

void test_base64()
Expand Down

0 comments on commit fa21ca2

Please sign in to comment.