From 39698fd166bb53c31a46c5596c1dfa296184e90b Mon Sep 17 00:00:00 2001 From: Franz Detro Date: Fri, 2 Aug 2024 16:53:14 +0200 Subject: [PATCH] fix Property Exchange chunk validation (0 is a valid 'number_of_chunks' value) --- src/capability_inquiry.cpp | 6 +++--- tests/ci_property_exchange_tests.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/capability_inquiry.cpp b/src/capability_inquiry.cpp index dff63a7..d99f6ee 100644 --- a/src/capability_inquiry.cpp +++ b/src/capability_inquiry.cpp @@ -229,7 +229,7 @@ bool property_exchange::property_data_message_view::validate(const sysex7& sx) const auto cur_chunk = sx.make_uint14(field_offsets::this_chunk + header_bytes); const auto chunk_bytes = sx.make_uint14(field_offsets::chunk_size + header_bytes); - if (cur_chunk > num_chunks) + if (num_chunks && (cur_chunk > num_chunks)) return false; if (header_bytes && (cur_chunk > 1)) @@ -258,8 +258,8 @@ message property_exchange::make_property_data_message(subtype_t subtype, auto result = message::make_with_payload_size(9 + header.size + chunk.size, subtype, source_muid, destination_muid, device_id); - assert((number_of_chunks && number_of_this_chunk) || ((chunk.data == nullptr) && (chunk.size == 0))); - assert(number_of_this_chunk <= number_of_chunks); + assert(number_of_this_chunk || ((chunk.data == nullptr) && (chunk.size == 0))); + assert((number_of_chunks == 0) || (number_of_this_chunk <= number_of_chunks)); assert(!header.size || header.data); assert(!chunk.size || chunk.data); diff --git a/tests/ci_property_exchange_tests.cpp b/tests/ci_property_exchange_tests.cpp index d094bc2..86303c9 100644 --- a/tests/ci_property_exchange_tests.cpp +++ b/tests/ci_property_exchange_tests.cpp @@ -902,7 +902,7 @@ TEST_F(ci_property_exchange, get_property_data_reply) auto sx = midi::ci::make_get_property_data_reply(0x1133577, 0xFFAABB0, - 256, + 0, 128, midi::ci::property_exchange::chunk{ chunk, @@ -927,7 +927,7 @@ TEST_F(ci_property_exchange, get_property_data_reply) EXPECT_EQ(0u, m.header_size()); EXPECT_EQ(m.header_end(), m.header_begin() + m.header_size()); - EXPECT_EQ(256u, m.number_of_chunks()); + EXPECT_EQ(0u, m.number_of_chunks()); EXPECT_EQ(128u, m.number_of_this_chunk()); EXPECT_EQ(chunk.size(), m.chunk_size());