Skip to content

[Bug]: registerLocalMemoryBatch accepts invalid buffer lists #2853

Description

@feichai0017

Bug Report

On current main (4188e3ae), TransferEngineImpl::registerLocalMemoryBatch() accepts overlapping entries within the same batch and also accepts zero-length entries.

checkOverlap() only checks local_memory_regions_, while the new entries are inserted after the entire validation loop. As a result, entries in the incoming batch are never checked against each other. The batch API also lacks the zero-length check performed by registerLocalMemory().

Reproduction

std::array<char, 256> buffer{};

std::vector<BufferEntry> overlapping = {
    {buffer.data(), 128},
    {buffer.data() + 64, 128},
};
EXPECT_EQ(engine.registerLocalMemoryBatch(overlapping, "cpu:0"),
          ERR_ADDRESS_OVERLAPPED);

std::vector<BufferEntry> zero_length = {
    {buffer.data(), 0},
};
EXPECT_EQ(engine.registerLocalMemoryBatch(zero_length, "cpu:0"),
          ERR_INVALID_ARGUMENT);

Both calls currently return 0.

Expected behavior

Validate the complete batch before invoking any transport:

  • Return ERR_ADDRESS_OVERLAPPED when entries overlap each other or an existing registration.
  • Return ERR_INVALID_ARGUMENT for a zero-length entry, consistent with registerLocalMemory().
  • Continue allowing adjacent, non-overlapping entries.

I searched open issues and PRs for registerLocalMemoryBatch overlap/zero-length handling and did not find an existing report or fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions