Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reattaching the allocator after compact #3828

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Fix upgrade bug. Could cause assertions like "Assertion failed: ref != 0" during opning of a realm. ([#6644](https://github.com/realm/realm-cocoa/issues/6644), since V6.0.7)
* A use-after-free would occur if a Realm was compacted, opened on multiple threads prior to the first write, then written to while reads were happening on other threads. This could result in a variety of crashes, often inside realm::util::EncryptedFileMapping::read_barrier. (Since v6.0.0, [Cocoa #6652](https://github.com/realm/realm-cocoa/issues/6652), [Cocoa #6628](https://github.com/realm/realm-cocoa/issues/6628), [Cocoa #6655](https://github.com/realm/realm-cocoa/issues/6555)).

### Breaking changes
* None.
Expand Down
1 change: 1 addition & 0 deletions src/realm/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ bool DB::compact(bool bump_version_number, util::Optional<const char*> output_en
cfg.encryption_key = write_key;
ref_type top_ref;
top_ref = m_alloc.attach_file(m_db_path, cfg);
m_alloc.m_youngest_live_version = info->latest_version_number;
info->number_of_versions = 1;
// info->latest_version_number is unchanged
SharedInfo* r_info = m_reader_map.get_addr();
Expand Down
25 changes: 25 additions & 0 deletions test/test_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,31 @@ TEST(Shared_CompactingOnTheFly)
}


TEST(Shared_ReadAfterCompact)
{
SHARED_GROUP_TEST_PATH(path);
DBRef sg = DB::create(path);
{
WriteTransaction wt(sg);
auto table = wt.add_table("table");
table->add_column(type_Int, "col");
table->create_object().set_all(1);
wt.commit();
}
sg->compact();
auto rt = sg->start_read();
auto table = rt->get_table("table");
for (int i = 2; i < 4; ++i) {
WriteTransaction wt(sg);
wt.get_table("table")->create_object().set_all(i);
wt.commit();
}

CHECK_EQUAL(table->size(), 1);
CHECK_EQUAL(table->get_object(0).get<int64_t>("col"), 1);
}


TEST(Shared_EncryptedRemap)
{
// Attempts to trigger code coverage in util::mremap() for the case where the file is encrypted.
Expand Down