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

Throw on invalid file #3203

Merged
merged 2 commits into from
Jan 3, 2019
Merged

Throw on invalid file #3203

merged 2 commits into from
Jan 3, 2019

Conversation

jedelbo
Copy link
Contributor

@jedelbo jedelbo commented Dec 21, 2018

This will leave it up to the user to decide what to do

}
default: {
std::string err =
"Invalid top array size (ref, size): " + util::to_string(top_ref) + ", " + util::to_string(top_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Invalid top array size (ref, size): " + util::to_string(top_ref) + ", " + util::to_string(top_size);
"Invalid top array size (ref=" + util::to_string(top_ref) + ", size=" + util::to_string(top_size) + "): ";

@bmunkholm
Copy link
Contributor

What about the other asserts in open now that we are at it. If they assert anything about the content of the file, they should also throw instead of asserting.

REALM_ASSERT_RELEASE_EX(!"Invalid top array size", top_ref, top_size);
break;
}
validate_top_array(m_top, m_alloc);
m_table_names.init_from_parent();
m_tables.init_from_parent();
REALM_ASSERT_RELEASE_EX(m_table_names.size() == m_tables.size(), top_ref, m_table_names.size(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also throw instead of asserting?

CHANGELOG.md Outdated
@@ -1,7 +1,7 @@
# NEXT RELEASE

### Enhancements
* None.
* An exception is thrown when a realm file has invalid top ref.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* An exception is thrown when a realm file has invalid top ref.
* Instead of asserting, an ??? exception is thrown when a realm file is opened with an invalid top ref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new commit with this change has been made

@jedelbo jedelbo merged commit eb519f0 into master Jan 3, 2019
@jedelbo jedelbo deleted the je/throw-on-invalid-file branch January 3, 2019 08:51
m_buffer += (std::string(" Path: ") + m_path);
return m_buffer.c_str();
}

Copy link
Contributor

@kspangsege kspangsege Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedelbo, are you aware that this construct makes the exception class not thread-compatible?

Modern C++ paradigm dictates these rules:

A necessary requirement for a type to be thread-compatible, is that all its const methods are thread-safe, meaning that two threads can safely call const methods on that type concurrently, as long as no other thread is calling a non-const method.

A class should be considered thread-compatible unless it is clear from the context that it is not, such as via documentation.

Roughly speaking, a type is thread-compatible if it is not thread-hostile. A type is thread-hostile if it does not offer the same intuitive level of thread-safety as is offered by fundamental types (integers) and almost all STL types (e.g., std::string).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was aware of that.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants