Skip to content

Commit

Permalink
fix Property Exchange chunk validation (0 is a valid 'number_of_chunk…
Browse files Browse the repository at this point in the history
…s' value)
  • Loading branch information
fdetro committed Aug 2, 2024
1 parent fc0a6b7 commit 39698fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/capability_inquiry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/ci_property_exchange_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
Expand Down

0 comments on commit 39698fd

Please sign in to comment.