Skip to content

Commit 4cc5e4a

Browse files
committed
Fix AV in rmw_topic_endpoint_info_array_t handling for iron and later distros
1 parent 030cae2 commit 4cc5e4a

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/Rcl.NET/Graph/RosGraph.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private unsafe void FetchTopicEndpoints(RosTopic topic, bool disableTopicNameDem
353353
var namePtr = nameBuffer.IsEmpty ? null : (byte*)Unsafe.AsPointer(ref nameBuffer[0]);
354354

355355
var allocator = RclAllocator.Default.Object;
356-
var accessor = RosEnvironment.IsSupported(RosEnvironment.Iron)
356+
ITopicEndPointDataAccessor accessor = RosEnvironment.IsSupported(RosEnvironment.Iron)
357357
? IronTopicEndPointDataAccessor.Instance
358358
: TopicEndPointDataAccessor.Instance;
359359

@@ -372,7 +372,8 @@ private unsafe void FetchTopicEndpoints(RosTopic topic, bool disableTopicNameDem
372372
{
373373
for (var i = 0; i < (int)endpoints.size.Value; i++)
374374
{
375-
items.Span[i] = new(&endpoints.info_array[i], accessor);
375+
// Access info_array through accessor to deal with layout difference between different distros.
376+
items.Span[i] = new(accessor.GetInfoFromArray(endpoints.info_array, i), accessor);
376377
}
377378
topic.UpdatePublishers(this, items.Span, _nodes);
378379
}
@@ -432,6 +433,11 @@ private unsafe class TopicEndPointDataAccessor : ITopicEndPointDataAccessor
432433
{
433434
public static readonly TopicEndPointDataAccessor Instance = new();
434435

436+
public void* GetInfoFromArray(void* array, int index)
437+
{
438+
return &((rmw_topic_endpoint_info_t*)array)[index];
439+
}
440+
435441
public GraphId GetGraphId(void* data)
436442
{
437443
var item = (rmw_topic_endpoint_info_t*)data;
@@ -461,7 +467,12 @@ public QosProfile GetQosProfile(void* data)
461467

462468
private unsafe class IronTopicEndPointDataAccessor : ITopicEndPointDataAccessor
463469
{
464-
public static readonly TopicEndPointDataAccessor Instance = new();
470+
public static readonly IronTopicEndPointDataAccessor Instance = new();
471+
472+
public void* GetInfoFromArray(void* array, int index)
473+
{
474+
return &((RclIron.rmw_topic_endpoint_info_t*)array)[index];
475+
}
465476

466477
public GraphId GetGraphId(void* data)
467478
{

src/Rcl.NET/Graph/TopicEndPointData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ record struct NameWithType(string Name, string Type);
66

77
unsafe interface ITopicEndPointDataAccessor
88
{
9+
void* GetInfoFromArray(void* array, int index);
10+
911
GraphId GetGraphId(void* data);
1012

1113
string GetType(void* data);

0 commit comments

Comments
 (0)