-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arithmetic overflow in fragment size calculations (#5464)
* Tests arithmetic overflow in fragment size calculations Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Refs #21814. Fix code in BaseWriter.cpp. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Fix corner case overhead==max_data_size Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Refs #21814. Fix code in WriterHistory.cpp. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Fix corner case overhead==final_high_mark_for_frag Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Uncrustify Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Fix log error message Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Fix test fragments not been dropped Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Fix corner case RTPSParticipantImpl max_data_size < overhead Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Test refactor for windows compilation Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Fix blackbox test Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> * Applied review suggestions Signed-off-by: EugenioCollado <121509066+EugenioCollado@users.noreply.github.com> --------- Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com> Signed-off-by: Miguel Company <miguelcompany@eprosima.com> Signed-off-by: EugenioCollado <121509066+EugenioCollado@users.noreply.github.com> Co-authored-by: Miguel Company <miguelcompany@eprosima.com> (cherry picked from commit bfc5a53)
- Loading branch information
1 parent
28552ce
commit 2da4ffc
Showing
5 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <fastrtps/rtps/RTPSDomain.h> | ||
#include <fastrtps/rtps/participant/RTPSParticipant.h> | ||
#include <fastrtps/rtps/writer/RTPSWriter.h> | ||
#include <fastrtps/rtps/history/WriterHistory.h> | ||
|
||
|
||
namespace eprosima { | ||
namespace fastrtps { | ||
namespace rtps { | ||
|
||
using namespace testing; | ||
|
||
#define MAX_MESSAGE_SIZE 300 | ||
|
||
void cache_change_fragment( | ||
uint32_t max_message_size, | ||
uint32_t inline_qos_length, | ||
bool expected_fragmentation) | ||
{ | ||
uint32_t domain_id = 0; | ||
uint32_t initial_reserved_caches = 10; | ||
std::string max_message_size_str = std::to_string(max_message_size); | ||
|
||
RTPSParticipantAttributes p_attr; | ||
p_attr.properties.properties().emplace_back("fastdds.max_message_size", max_message_size_str); | ||
RTPSParticipant* participant = RTPSDomain::createParticipant( | ||
domain_id, true, p_attr); | ||
|
||
ASSERT_NE(participant, nullptr); | ||
|
||
HistoryAttributes h_attr; | ||
h_attr.memoryPolicy = DYNAMIC_RESERVE_MEMORY_MODE; | ||
h_attr.initialReservedCaches = initial_reserved_caches; | ||
h_attr.payloadMaxSize = 250; | ||
WriterHistory* history = new WriterHistory(h_attr); | ||
|
||
WriterAttributes w_attr; | ||
RTPSWriter* writer = RTPSDomain::createRTPSWriter(participant, w_attr, history); | ||
|
||
ASSERT_NE(writer, nullptr); | ||
|
||
CacheChange_t* change = writer->new_change(ALIVE); | ||
if (expected_fragmentation) | ||
{ | ||
change->serializedPayload.length = 3 * max_message_size; | ||
} | ||
else | ||
{ | ||
change->serializedPayload.length = max_message_size / 3; | ||
} | ||
change->inline_qos.length = inline_qos_length; | ||
history->add_change(change); | ||
|
||
auto result = change->getFragmentSize(); | ||
std::cout << "Fragment size: " << result << std::endl; | ||
if (expected_fragmentation) | ||
{ | ||
ASSERT_NE(result, 0); | ||
} | ||
else | ||
{ | ||
ASSERT_EQ(result, 0); | ||
} | ||
} | ||
|
||
/** | ||
* This test checks the fragment size calculation for a cache change depending on the inline qos length. | ||
* The change.serializedPayload.length is set to 3 times the max_allowed_payload_size, so the fragment size should always be set. | ||
* In case of an overflow in the attribute high_mark_for_frag_ the fragment size will not be set, which is an error. | ||
*/ | ||
TEST(WriterHistoryTests, final_high_mark_for_frag_overflow) | ||
{ | ||
for (uint32_t inline_qos_length = 0; inline_qos_length < MAX_MESSAGE_SIZE; inline_qos_length += 40) | ||
{ | ||
cache_change_fragment(MAX_MESSAGE_SIZE, inline_qos_length, true); | ||
} | ||
} | ||
|
||
} // namespace rtps | ||
} // namespace fastdds | ||
} // namespace eprosima | ||
|
||
int main( | ||
int argc, | ||
char** argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |