Skip to content

Commit 9b740c1

Browse files
authored
Merge pull request #2279 from joto/check-flatnode-format
Check flat node file format for forwards compatibility
2 parents 6a0c731 + b8bb093 commit 9b740c1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/node-persistent-cache.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ node_persistent_cache::node_persistent_cache(std::string file_name,
4545
}
4646

4747
m_index = std::make_unique<index_t>(m_fd);
48+
49+
// First location must always be the undefined location, otherwise we
50+
// might be looking at a different kind of file. This check here is for
51+
// forwards compatibility. If and when we change the file format, we
52+
// can use the first 8 bytes to differentiate the file format.
53+
auto const loc = get(0);
54+
if (loc.is_defined()) {
55+
throw fmt_error("Not a version 1 flatnode file '{}'", m_file_name);
56+
}
4857
}
4958

5059
node_persistent_cache::~node_persistent_cache() noexcept

0 commit comments

Comments
 (0)