Mercurial > hg > orthanc
diff OrthancFramework/UnitTestsSources/RestApiTests.cpp @ 4151:8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Aug 2020 11:59:02 +0200 |
parents | b56f3a37a4a1 |
children | 86e99e08ba52 |
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/RestApiTests.cpp Wed Aug 19 11:18:55 2020 +0200 +++ b/OrthancFramework/UnitTestsSources/RestApiTests.cpp Wed Aug 19 11:59:02 2020 +0200 @@ -1034,7 +1034,7 @@ const void* bodyData, size_t bodySize) { - printf("received %llu\n", bodySize); + printf("received %lu\n", bodySize); const uint8_t* b = reinterpret_cast<const uint8_t*>(bodyData); @@ -1055,7 +1055,37 @@ #include "../Sources/HttpServer/HttpServer.h" -TEST(Toto, DISABLED_Toto) +TEST(HttpClient, DISABLED_Issue156_Slow) +{ + // https://bugs.orthanc-server.com/show_bug.cgi?id=156 + + TotoServer handler; + HttpServer server; + server.SetPortNumber(5000); + server.Register(handler); + server.Start(); + + WebServiceParameters w; + w.SetUrl("http://localhost:5000"); + + // This is slow in Orthanc <= 1.5.8 (issue 156) + TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17); + + HttpClient c(w, "toto"); + c.SetMethod(HttpMethod_Post); + c.AddHeader("Expect", ""); + c.AddHeader("Transfer-Encoding", "chunked"); + c.SetBody(body); + + std::string s; + ASSERT_TRUE(c.Apply(s)); + ASSERT_EQ("ok", s); + + server.Stop(); +} + + +TEST(HttpClient, DISABLED_Issue156_Crash) { TotoServer handler; HttpServer server; @@ -1065,20 +1095,19 @@ WebServiceParameters w; w.SetUrl("http://localhost:5000"); - - //TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17); - TotoBody body(32 * 1024, 1); // This crashes Orthanc 1.6.0 to 1.7.2 + + // This crashes Orthanc 1.6.0 to 1.7.2 + TotoBody body(32 * 1024, 1); HttpClient c(w, "toto"); c.SetMethod(HttpMethod_Post); c.AddHeader("Expect", ""); c.AddHeader("Transfer-Encoding", "chunked"); c.SetBody(body); - + std::string s; ASSERT_TRUE(c.Apply(s)); - - printf(">> [%s]\n", s.c_str()); + ASSERT_EQ("ok", s); server.Stop(); }