matrix-org / matrix-org/matrix-rust-sdk

`MemoryStore` allows duplicate `ChunkIdentifier`'s

Open
#6,095 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

MemoryStore currently relies on RelationalLinkedChunk::apply_updates to manage Update's to its internal data. This function, in turn, relies on RelationalLinkedChunk::insert_chunk when adding new chunks, which does not check whether the given ChunkIdentifier exists already.

To confirm this behavior, one can add the following integration test to EventCacheStoreIntegrationTests.

impl EventCacheStoreIntegrationTests for DynEventCacheStore {
    async fn test_linked_chunk_identifiers_are_unique(&self) {
        self.handle_linked_chunk_updates(
            LinkedChunkId::Room(room_id!("!r0:matrix.org")),
            vec![
                Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None },
                Update::NewItemsChunk { previous: None, new: ChunkIdentifier::new(0), next: None },
            ],
        )
        .await
        .unwrap_err();
    }

    // -- snip --
}

My guess is that this behavior is not desirable. It also happens to be inconsistent with other implementations of EventCacheStore.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RelationalLinkedChunk::apply_updates and insert_chunk in crates/matrix-sdk-common/src/linked_chunk/relational.rs, then review EventCacheStoreIntegrationTests and the other EventCacheStore implementations. Run the proposed uniqueness integration test; done means duplicate ChunkIdentifier updates are rejected consistently with those implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.