Mercurial > hg > orthanc
changeset 4333:a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 06:57:23 +0100 |
parents | 17d209a3f397 |
children | b2366bc023f8 |
files | OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp OrthancFramework/UnitTestsSources/RestApiTests.cpp |
diffstat | 2 files changed, 46 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp Wed Nov 25 21:42:50 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp Fri Nov 27 06:57:23 2020 +0100 @@ -297,6 +297,17 @@ } + static void RemoveSurroundingQuotes(std::string& value) + { + if (value.size() >= 2 && + value[0] == '"' && + value[value.size() - 1] == '"') + { + value = value.substr(1, value.size() - 2); + } + } + + bool MultipartStreamReader::ParseMultipartContentType(std::string& contentType, std::string& subType, std::string& boundary, @@ -331,6 +342,10 @@ if (boost::iequals("boundary", Toolbox::StripSpaces(items[0]))) { boundary = Toolbox::StripSpaces(items[1]); + + // https://bugs.orthanc-server.com/show_bug.cgi?id=190 + RemoveSurroundingQuotes(boundary); + valid = !boundary.empty(); } else if (boost::iequals("type", Toolbox::StripSpaces(items[0]))) @@ -340,12 +355,7 @@ // https://bitbucket.org/sjodogne/orthanc/issues/54/decide-what-to-do-wrt-quoting-of-multipart // https://tools.ietf.org/html/rfc7231#section-3.1.1.1 - if (subType.size() >= 2 && - subType[0] == '"' && - subType[subType.size() - 1] == '"') - { - subType = subType.substr(1, subType.size() - 2); - } + RemoveSurroundingQuotes(subType); } } }
--- a/OrthancFramework/UnitTestsSources/RestApiTests.cpp Wed Nov 25 21:42:50 2020 +0100 +++ b/OrthancFramework/UnitTestsSources/RestApiTests.cpp Fri Nov 27 06:57:23 2020 +0100 @@ -894,6 +894,36 @@ } +TEST(MultipartStreamReader, Issue190) +{ + // https://bugs.orthanc-server.com/show_bug.cgi?id=190 + // https://hg.orthanc-server.com/orthanc-dicomweb/rev/6dc2f79b5579 + + std::map<std::string, std::string> headers; + headers["content-type"] = "multipart/related; type=application/dicom; boundary=0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1"; + + { + std::string tmp, contentType, subType, boundary; + ASSERT_TRUE(Orthanc::MultipartStreamReader::GetMainContentType(tmp, headers)); + ASSERT_TRUE(Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, tmp)); + ASSERT_EQ("multipart/related", contentType); + ASSERT_EQ("application/dicom", subType); + ASSERT_EQ("0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1", boundary); + } + + headers["content-type"] = "multipart/related; type=\"application/dicom\"; boundary=\"0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1\""; + + { + std::string tmp, contentType, subType, boundary; + ASSERT_TRUE(Orthanc::MultipartStreamReader::GetMainContentType(tmp, headers)); + ASSERT_TRUE(Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, tmp)); + ASSERT_EQ("multipart/related", contentType); + ASSERT_EQ("application/dicom", subType); + ASSERT_EQ("0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1", boundary); + } +} + + TEST(WebServiceParameters, Url) { WebServiceParameters w;