Skip to content

Commit

Permalink
Add sanity checks to JSBigFileString
Browse files Browse the repository at this point in the history
Summary:
When asking for the data of a JSBigFileString, check that the instance satisfies some basic invariants.

This is meant to catch any corruption issues as early as possible.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22125436

fbshipit-source-id: e0a84752c86151d56b7e7cbed3b95650d8ba1f75
  • Loading branch information
kodafb authored and facebook-github-bot committed Jun 19, 2020
1 parent b095432 commit 709570a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ReactCommon/cxxreact/JSBigString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ const char *JSBigFileString::c_str() const {
}
#endif // WITH_FBREMAP
}
static const size_t kMinPageSize = 4096;
CHECK(!(reinterpret_cast<uintptr_t>(m_data) & (kMinPageSize - 1)))
<< "mmap address misaligned, likely corrupted"
<< " m_data: " << (const void *)m_data;
CHECK(m_pageOff <= m_size)
<< "offset impossibly large, likely corrupted"
<< " m_pageOff: " << m_pageOff << " m_size: " << m_size;
return m_data + m_pageOff;
}

Expand Down

0 comments on commit 709570a

Please sign in to comment.