Skip to content

Fix type-ids check in load_data for Message#1614

Merged
Neverlord merged 3 commits into
actor-framework:masterfrom
allspark:fixMessageLoadData
Oct 22, 2023
Merged

Fix type-ids check in load_data for Message#1614
Neverlord merged 3 commits into
actor-framework:masterfrom
allspark:fixMessageLoadData

Conversation

@allspark

Copy link
Copy Markdown
Contributor

Hi,

i discovered that the load_data https://github.com/actor-framework/actor-framework/blob/0.19.4/libcaf_core/caf/message.cpp#L73 iterates over the placeholder for the actual-size of the type_id_list.

the first 'id' in the `type_id_list_builder` is the placeholder for the
actual size of the `type_id_list` which is always zero.
@Neverlord

Copy link
Copy Markdown
Member

Wow, thanks a lot for hunting this down!

i discovered ...

Our of curiosity: how? 🙂

If I read this correctly, there are two bugfixes here:

  1. CAF re-allocated memory for the type ID list too early (the off-by-one part)
  2. CAF allocated too much memory for deserialized messages because it always added the padded size for whatever type has type ID 0

These are very subtle bugs, so how did you find them? Memory profiling?

@codecov

codecov Bot commented Oct 21, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (3fa129d) 66.65% compared to head (4886323) 67.27%.
Report is 78 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1614      +/-   ##
==========================================
+ Coverage   66.65%   67.27%   +0.61%     
==========================================
  Files         644      652       +8     
  Lines       27538    27774     +236     
  Branches     2925     3013      +88     
==========================================
+ Hits        18356    18684     +328     
+ Misses       7686     7541     -145     
- Partials     1496     1549      +53     
Files Coverage Δ
libcaf_core/caf/detail/type_id_list_builder.cpp 79.68% <100.00%> (-1.57%) ⬇️
libcaf_core/caf/detail/type_id_list_builder.hpp 66.66% <ø> (+9.52%) ⬆️
libcaf_core/caf/message.cpp 66.88% <66.66%> (+0.44%) ⬆️

... and 107 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@allspark

allspark commented Oct 21, 2023

Copy link
Copy Markdown
Contributor Author

I explored how the std::set<std::string> (from caf::actor_system::mpi) for message_types is used and how void is encoded as type_id_t. Then changed the 0 in CAF_BEGIN_TYPE_ID_BLOCK(core_module, 0) to 1 and got a segfault, in some unrelated function but pinned it down to the load_data function

The segfault occured at

src->enqueue(nullptr, mid.response_id(),
because src was NULL with the "distributed_calculator" when the client connects to the server

Comment thread libcaf_core/caf/detail/type_id_list_builder.cpp
@Neverlord Neverlord added this to the 0.19.5 milestone Oct 22, 2023
@Neverlord Neverlord merged commit 4b17226 into actor-framework:master Oct 22, 2023
@allspark allspark deleted the fixMessageLoadData branch October 22, 2023 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants