Skip to content

Commit b8bb093

Browse files
committed
Check flat node file format for forwards compatibility
In a flat node file the first location is that of node id 0, which does not exist. So the first location must always be the undefined location, otherwise we might be looking at a different kind of file. This adds a check for forwards compatibility. If and when we change the file format, we can use the first 8 bytes to differentiate the file formats.
1 parent 6a0c731 commit b8bb093

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)