Skip to content

Commit

Permalink
RCORE-1977 Empty reciprocal changesets lead to crashes or data diverg…
Browse files Browse the repository at this point in the history
…ence (#7955)

* Fix bugs related to storing and retrieving reciprocal changesets
  • Loading branch information
danieltabacaru authored Aug 8, 2024
1 parent 430a044 commit 13d8264
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Fixed an "invalid column key" exception when using a RQL "BETWEEN" query on an int or timestamp property across links. ([#7935](https://github.com/realm/realm-core/issues/7935), since v14.10.1)
* Fixed conflict resolution bug related to ArrayErase and Clear instructions, which could sometimes cause an "Invalid prior_size" exception to prevent synchronization ([#7893](https://github.com/realm/realm-core/issues/7893), since v14.8.0).
* Fixed bug which would prevent eventual consistency during conflict resolution. Affected clients would experience data divergence and potentially consistency errors as a result. ([PR #7955](https://github.com/realm/realm-core/pull/7955), since v14.8.0)

### Breaking changes
* None.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/sync/noinst/client_history_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void ClientHistory::set_reciprocal_transform(version_type version, BinaryData da
std::size_t index = size_t(version - m_sync_history_base_version) - 1;
REALM_ASSERT(index < sync_history_size());

if (data.is_null()) {
if (data.size() == 0) {
m_arrays->reciprocal_transforms.set(index, BinaryData{"", 0}); // Throws
return;
}
Expand Down
7 changes: 4 additions & 3 deletions src/realm/sync/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2590,8 +2590,9 @@ size_t Transformer::transform_remote_changesets(TransformHistory& history, file_
Changeset& Transformer::get_reciprocal_transform(TransformHistory& history, file_ident_type local_file_ident,
version_type version, const HistoryEntry& history_entry)
{
auto& changeset = m_reciprocal_transform_cache[version]; // Throws
if (changeset.empty()) {
auto [it, success] = m_reciprocal_transform_cache.insert({version, Changeset{}}); // Throws
if (success) {
Changeset& changeset = it->second;
bool is_compressed = false;
ChunkedBinaryData data = history.get_reciprocal_transform(version, is_compressed);
ChunkedBinaryInputStream in{data};
Expand All @@ -2613,7 +2614,7 @@ Changeset& Transformer::get_reciprocal_transform(TransformHistory& history, file
origin_file_ident = local_file_ident;
changeset.origin_file_ident = origin_file_ident;
}
return changeset;
return it->second;
}


Expand Down
Loading

0 comments on commit 13d8264

Please sign in to comment.