{"action":"created","issue":{"url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/201","repository_url":"https://api.github.com/repos/openigtlink/OpenIGTLink","labels_url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/201/labels{/name}","comments_url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/201/comments","events_url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/201/events","html_url":"https://github.com/openigtlink/OpenIGTLink/issues/201","id":383745598,"node_id":"MDU6SXNzdWUzODM3NDU1OTg=","number":201,"title":"Serialization of igtl::ImageMessage is broken with new header version and meta data included","user":{"login":"Abroxa","id":25658526,"node_id":"MDQ6VXNlcjI1NjU4NTI2","avatar_url":"https://avatars0.githubusercontent.com/u/25658526?v=4","gravatar_id":"","url":"https://api.github.com/users/Abroxa","html_url":"https://github.com/Abroxa","followers_url":"https://api.github.com/users/Abroxa/followers","following_url":"https://api.github.com/users/Abroxa/following{/other_user}","gists_url":"https://api.github.com/users/Abroxa/gists{/gist_id}","starred_url":"https://api.github.com/users/Abroxa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Abroxa/subscriptions","organizations_url":"https://api.github.com/users/Abroxa/orgs","repos_url":"https://api.github.com/users/Abroxa/repos","events_url":"https://api.github.com/users/Abroxa/events{/privacy}","received_events_url":"https://api.github.com/users/Abroxa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-11-23T09:06:30Z","updated_at":"2018-12-06T14:14:44Z","closed_at":null,"author_association":"NONE","body":"An igtl::ImageMessage that is serialized and deserialized is broken (does not have any meaningful values) if these two conditions are fulfilled:\r\n\r\n1. The message uses IGTL_HEADER_VERSION_2.\r\n2. The message actually has some metadata included\r\n\r\nIf the message uses IGTL_HEADER_VERSION_1 OR it does not have any meta data included (header v2 without metadata elements) deserialization seems to be ok.\r\n\r\nThe following test code can be used to reproduce the problem:\r\n```c++\r\nTEST(OpenIGTLinkSerializationTest, OpenIGTLinkImageAndMetaDataGetsPackedAndRestored)\r\n{\r\n  // Message construction\r\n  auto msg = igtl::ImageMessage::New();\r\n  msg->SetHeaderVersion(IGTL_HEADER_VERSION_2);\r\n  msg->SetScalarTypeToUint16();\r\n  msg->SetDimensions(2, 3, 4);\r\n  msg->SetNumComponents(1);\r\n  msg->AllocateScalars();\r\n  uint16_t* data = static_cast<uint16_t*>(msg->GetScalarPointer());\r\n  for (uint16_t i = 0; i < ext_x*ext_y*ext_z; ++i, ++data) {\r\n    *data = 42;\r\n  }\r\n  msg->SetMetaDataElement(\"key\", IANA_TYPE_UTF_8, \"value\");\r\n  msg->Pack();\r\n\r\n  // Message transport\r\n  auto header = igtl::MessageHeader::New();\r\n  header->InitPack();\r\n  std::memcpy(header->GetPackPointer(), msg->GetPackPointer(), header->GetPackSize());\r\n  header->Unpack();\r\n\r\n  EXPECT_EQ(IGTL_HEADER_VERSION_2, header->GetHeaderVersion());\r\n\r\n  auto target = igtl::ImageMessage::New();\r\n  target->SetMessageHeader(header);\r\n  target->AllocatePack();\r\n\r\n  ASSERT_EQ(target->GetPackBodySize(), msg->GetPackBodySize());\r\n\r\n  std::memcpy(target->GetPackBodyPointer(), msg->GetPackBodyPointer(), target->GetPackBodySize());\r\n  target->Unpack();\r\n\r\n  // Message comparison\r\n  EXPECT_EQ(IGTL_HEADER_VERSION_2, target->GetHeaderVersion());\r\n\r\n  int ext_x, ext_y, ext_z;\r\n  target->GetDimensions(ext_x, ext_y, ext_z);\r\n  EXPECT_EQ(2, ext_x); // fails!\r\n  EXPECT_EQ(3, ext_y); // fails!\r\n  EXPECT_EQ(4, ext_z); // fails!\r\n\r\n  uint16_t* data = static_cast<uint16_t*>(target->GetScalarPointer());\r\n  for (uint16_t i = 0; i < 2*3*4; ++i, ++data) {\r\n    EXPECT_EQ(42, *data); // even leads to access violations!\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/comments/444884120","html_url":"https://github.com/openigtlink/OpenIGTLink/issues/201#issuecomment-444884120","issue_url":"https://api.github.com/repos/openigtlink/OpenIGTLink/issues/201","id":444884120,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDg4NDEyMA==","user":{"login":"leochan2009","id":10211992,"node_id":"MDQ6VXNlcjEwMjExOTky","avatar_url":"https://avatars0.githubusercontent.com/u/10211992?v=4","gravatar_id":"","url":"https://api.github.com/users/leochan2009","html_url":"https://github.com/leochan2009","followers_url":"https://api.github.com/users/leochan2009/followers","following_url":"https://api.github.com/users/leochan2009/following{/other_user}","gists_url":"https://api.github.com/users/leochan2009/gists{/gist_id}","starred_url":"https://api.github.com/users/leochan2009/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leochan2009/subscriptions","organizations_url":"https://api.github.com/users/leochan2009/orgs","repos_url":"https://api.github.com/users/leochan2009/repos","events_url":"https://api.github.com/users/leochan2009/events{/privacy}","received_events_url":"https://api.github.com/users/leochan2009/received_events","type":"User","site_admin":false},"created_at":"2018-12-06T14:14:44Z","updated_at":"2018-12-06T14:14:44Z","author_association":"CONTRIBUTOR","body":"@Abroxa , i think it doesn't matter, the image message is order independent now.  The buffer reallocation won't allocate the memory multiple times if the buffer is already allocated. when the allocate operation is called multiple times, it is mainly for pointers alignment. "}}
{"actor":{"display_login":"leochan2009"}}