comparison OrthancFramework/Sources/HttpServer/MultipartStreamReader.cpp @ 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 50b0c69b653a
children 4301722b3225
comparison
equal deleted inserted replaced
4332:17d209a3f397 4333:a85e74235a78
295 return true; 295 return true;
296 } 296 }
297 } 297 }
298 298
299 299
300 static void RemoveSurroundingQuotes(std::string& value)
301 {
302 if (value.size() >= 2 &&
303 value[0] == '"' &&
304 value[value.size() - 1] == '"')
305 {
306 value = value.substr(1, value.size() - 2);
307 }
308 }
309
310
300 bool MultipartStreamReader::ParseMultipartContentType(std::string& contentType, 311 bool MultipartStreamReader::ParseMultipartContentType(std::string& contentType,
301 std::string& subType, 312 std::string& subType,
302 std::string& boundary, 313 std::string& boundary,
303 const std::string& contentTypeHeader) 314 const std::string& contentTypeHeader)
304 { 315 {
329 if (items.size() == 2) 340 if (items.size() == 2)
330 { 341 {
331 if (boost::iequals("boundary", Toolbox::StripSpaces(items[0]))) 342 if (boost::iequals("boundary", Toolbox::StripSpaces(items[0])))
332 { 343 {
333 boundary = Toolbox::StripSpaces(items[1]); 344 boundary = Toolbox::StripSpaces(items[1]);
345
346 // https://bugs.orthanc-server.com/show_bug.cgi?id=190
347 RemoveSurroundingQuotes(boundary);
348
334 valid = !boundary.empty(); 349 valid = !boundary.empty();
335 } 350 }
336 else if (boost::iequals("type", Toolbox::StripSpaces(items[0]))) 351 else if (boost::iequals("type", Toolbox::StripSpaces(items[0])))
337 { 352 {
338 subType = Toolbox::StripSpaces(items[1]); 353 subType = Toolbox::StripSpaces(items[1]);
339 Toolbox::ToLowerCase(subType); 354 Toolbox::ToLowerCase(subType);
340 355
341 // https://bitbucket.org/sjodogne/orthanc/issues/54/decide-what-to-do-wrt-quoting-of-multipart 356 // https://bitbucket.org/sjodogne/orthanc/issues/54/decide-what-to-do-wrt-quoting-of-multipart
342 // https://tools.ietf.org/html/rfc7231#section-3.1.1.1 357 // https://tools.ietf.org/html/rfc7231#section-3.1.1.1
343 if (subType.size() >= 2 && 358 RemoveSurroundingQuotes(subType);
344 subType[0] == '"' &&
345 subType[subType.size() - 1] == '"')
346 {
347 subType = subType.substr(1, subType.size() - 2);
348 }
349 } 359 }
350 } 360 }
351 } 361 }
352 362
353 return valid; 363 return valid;