comparison 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
comparison
equal deleted inserted replaced
4150:b56f3a37a4a1 4151:8c559dd5034b
1032 const Arguments& headers, 1032 const Arguments& headers,
1033 const GetArguments& getArguments, 1033 const GetArguments& getArguments,
1034 const void* bodyData, 1034 const void* bodyData,
1035 size_t bodySize) 1035 size_t bodySize)
1036 { 1036 {
1037 printf("received %llu\n", bodySize); 1037 printf("received %lu\n", bodySize);
1038 1038
1039 const uint8_t* b = reinterpret_cast<const uint8_t*>(bodyData); 1039 const uint8_t* b = reinterpret_cast<const uint8_t*>(bodyData);
1040 1040
1041 for (size_t i = 0; i < bodySize; i++) 1041 for (size_t i = 0; i < bodySize; i++)
1042 { 1042 {
1053 } 1053 }
1054 1054
1055 1055
1056 #include "../Sources/HttpServer/HttpServer.h" 1056 #include "../Sources/HttpServer/HttpServer.h"
1057 1057
1058 TEST(Toto, DISABLED_Toto) 1058 TEST(HttpClient, DISABLED_Issue156_Slow)
1059 { 1059 {
1060 // https://bugs.orthanc-server.com/show_bug.cgi?id=156
1061
1060 TotoServer handler; 1062 TotoServer handler;
1061 HttpServer server; 1063 HttpServer server;
1062 server.SetPortNumber(5000); 1064 server.SetPortNumber(5000);
1063 server.Register(handler); 1065 server.Register(handler);
1064 server.Start(); 1066 server.Start();
1065 1067
1066 WebServiceParameters w; 1068 WebServiceParameters w;
1067 w.SetUrl("http://localhost:5000"); 1069 w.SetUrl("http://localhost:5000");
1068 1070
1069 //TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17); 1071 // This is slow in Orthanc <= 1.5.8 (issue 156)
1070 TotoBody body(32 * 1024, 1); // This crashes Orthanc 1.6.0 to 1.7.2 1072 TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17);
1071 1073
1072 HttpClient c(w, "toto"); 1074 HttpClient c(w, "toto");
1073 c.SetMethod(HttpMethod_Post); 1075 c.SetMethod(HttpMethod_Post);
1074 c.AddHeader("Expect", ""); 1076 c.AddHeader("Expect", "");
1075 c.AddHeader("Transfer-Encoding", "chunked"); 1077 c.AddHeader("Transfer-Encoding", "chunked");
1076 c.SetBody(body); 1078 c.SetBody(body);
1077 1079
1078 std::string s; 1080 std::string s;
1079 ASSERT_TRUE(c.Apply(s)); 1081 ASSERT_TRUE(c.Apply(s));
1080 1082 ASSERT_EQ("ok", s);
1081 printf(">> [%s]\n", s.c_str());
1082 1083
1083 server.Stop(); 1084 server.Stop();
1084 } 1085 }
1086
1087
1088 TEST(HttpClient, DISABLED_Issue156_Crash)
1089 {
1090 TotoServer handler;
1091 HttpServer server;
1092 server.SetPortNumber(5000);
1093 server.Register(handler);
1094 server.Start();
1095
1096 WebServiceParameters w;
1097 w.SetUrl("http://localhost:5000");
1098
1099 // This crashes Orthanc 1.6.0 to 1.7.2
1100 TotoBody body(32 * 1024, 1);
1101
1102 HttpClient c(w, "toto");
1103 c.SetMethod(HttpMethod_Post);
1104 c.AddHeader("Expect", "");
1105 c.AddHeader("Transfer-Encoding", "chunked");
1106 c.SetBody(body);
1107
1108 std::string s;
1109 ASSERT_TRUE(c.Apply(s));
1110 ASSERT_EQ("ok", s);
1111
1112 server.Stop();
1113 }