Record the digest algorithm in the index snapshot
Snapshot schema 4 stores digestAlgorithm inside the digested payload. Restore accepts schemas 1-4, verifies the digest for 3 and 4, and classifies an unknown algorithm as incompatible instead of corrupt so a future digest change is not misread as corruption. Registered tests cover the migration and the rejection.
This commit is contained in:
1 parent
98ddf08eaf
commit
67ca5ea275
3 files changed
+42
-9
No files matched your search
@@ -61,6 +61,16 @@ start coordinate only, so ranges are zero-width until an end is available.
|
|||||||
LSP adapters and index/rename/debugging integration remain open. `vbs test`
|
LSP adapters and index/rename/debugging integration remain open. `vbs test`
|
||||||
passed all 17 native suites; CMake passed the reflection and trace suites.
|
passed all 17 native suites; CMake passed the reflection and trace suites.
|
||||||
|
|
||||||
|
## December 6 index snapshot schema 4
|
||||||
|
|
||||||
|
The symbol-index snapshot is now schema 4 and records `digestAlgorithm` inside
|
||||||
|
the digested payload. Restore accepts schemas 1-4 (older ones report
|
||||||
|
`migrated`), verifies the digest for schemas 3 and 4, and classifies an unknown
|
||||||
|
algorithm as `incompatible` rather than `corrupt`, so a future digest change
|
||||||
|
cannot be misread as corruption. Registered `vls_index_tests` cover the
|
||||||
|
migration path and the unknown-algorithm rejection (30 cases). All 18 native
|
||||||
|
suites and all 18 CMake tests passed.
|
||||||
|
|
||||||
## December 6 reflection references
|
## December 6 reflection references
|
||||||
|
|
||||||
`reflection::references_at` collects every source link of the entity covering a
|
`reflection::references_at` collects every source link of the entity covering a
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ using Json = P::Json;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr std::size_t max_json_depth = 8;
|
constexpr std::size_t max_json_depth = 8;
|
||||||
constexpr std::int64_t snapshot_schema = 3;
|
constexpr std::int64_t snapshot_schema = 4;
|
||||||
constexpr std::int64_t oldest_snapshot_schema = 1;
|
constexpr std::int64_t oldest_snapshot_schema = 1;
|
||||||
const char *backend_name = "vls-symbol-index";
|
const char *backend_name = "vls-symbol-index";
|
||||||
|
|
||||||
@@ -189,7 +189,12 @@ SnapshotStatus parse_snapshot(std::string_view bytes, const Limits &limits, Pars
|
|||||||
if (!schema_value || !backend || *backend != backend_name ||
|
if (!schema_value || !backend || *backend != backend_name ||
|
||||||
(*schema_value < oldest_snapshot_schema || *schema_value > snapshot_schema))
|
(*schema_value < oldest_snapshot_schema || *schema_value > snapshot_schema))
|
||||||
return SnapshotStatus::incompatible;
|
return SnapshotStatus::incompatible;
|
||||||
if (*schema_value == snapshot_schema) {
|
if (*schema_value >= 3) {
|
||||||
|
if (*schema_value == snapshot_schema) {
|
||||||
|
const auto *algorithm = P::as_string(P::find_member(*root, "digestAlgorithm"));
|
||||||
|
if (!algorithm || *algorithm != "sha256")
|
||||||
|
return SnapshotStatus::incompatible;
|
||||||
|
}
|
||||||
const auto *digest = P::as_string(P::find_member(*root, "digest"));
|
const auto *digest = P::as_string(P::find_member(*root, "digest"));
|
||||||
if (!digest || digest->size() != 64)
|
if (!digest || digest->size() != 64)
|
||||||
return SnapshotStatus::corrupt;
|
return SnapshotStatus::corrupt;
|
||||||
@@ -571,6 +576,7 @@ bool SymbolIndex::save(const fs::path &path) const {
|
|||||||
root = Json{Json::Object{{"schema", Json{snapshot_schema}},
|
root = Json{Json::Object{{"schema", Json{snapshot_schema}},
|
||||||
{"backend", Json{std::string{backend_name}}},
|
{"backend", Json{std::string{backend_name}}},
|
||||||
{"generation", Json{static_cast<std::int64_t>(state.generation)}},
|
{"generation", Json{static_cast<std::int64_t>(state.generation)}},
|
||||||
|
{"digestAlgorithm", Json{std::string{"sha256"}}},
|
||||||
{"contexts", Json{std::move(contexts)}},
|
{"contexts", Json{std::move(contexts)}},
|
||||||
{"overlays", Json{std::move(overlays)}}}};
|
{"overlays", Json{std::move(overlays)}}}};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ VOID_TEST(SymbolIndex, rejects_incompatible_or_corrupt_snapshots) {
|
|||||||
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
||||||
}();
|
}();
|
||||||
auto incompatible = bytes;
|
auto incompatible = bytes;
|
||||||
const auto schema = incompatible.find("\"schema\":3");
|
const auto schema = incompatible.find("\"schema\":4");
|
||||||
require(schema != std::string::npos);
|
require(schema != std::string::npos);
|
||||||
incompatible.replace(schema, 10, "\"schema\":9");
|
incompatible.replace(schema, 10, "\"schema\":9");
|
||||||
{
|
{
|
||||||
@@ -210,7 +210,7 @@ VOID_TEST(SymbolIndex, quarantines_incompatible_snapshots_and_rebuilds) {
|
|||||||
std::ifstream stream{path, std::ios::binary};
|
std::ifstream stream{path, std::ios::binary};
|
||||||
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
||||||
}();
|
}();
|
||||||
const auto schema = bytes.find("\"schema\":3");
|
const auto schema = bytes.find("\"schema\":4");
|
||||||
require(schema != std::string::npos);
|
require(schema != std::string::npos);
|
||||||
bytes.replace(schema, 10, "\"schema\":9");
|
bytes.replace(schema, 10, "\"schema\":9");
|
||||||
{
|
{
|
||||||
@@ -350,7 +350,7 @@ std::string downgrade(std::string bytes) {
|
|||||||
const auto end = bytes.find('"', digest + 12);
|
const auto end = bytes.find('"', digest + 12);
|
||||||
require(end != std::string::npos);
|
require(end != std::string::npos);
|
||||||
bytes.erase(digest, end + 1 - digest);
|
bytes.erase(digest, end + 1 - digest);
|
||||||
const auto schema = bytes.find("\"schema\":3");
|
const auto schema = bytes.find("\"schema\":4");
|
||||||
require(schema != std::string::npos);
|
require(schema != std::string::npos);
|
||||||
bytes.replace(schema, 10, "\"schema\":1");
|
bytes.replace(schema, 10, "\"schema\":1");
|
||||||
return bytes;
|
return bytes;
|
||||||
@@ -373,7 +373,7 @@ VOID_TEST(SymbolIndex, snapshot_schema_migration_is_reported_and_rewritten) {
|
|||||||
const auto upgraded = temp.path() / "upgraded.json";
|
const auto upgraded = temp.path() / "upgraded.json";
|
||||||
require(loaded.save(upgraded));
|
require(loaded.save(upgraded));
|
||||||
const auto bytes = file_text(upgraded);
|
const auto bytes = file_text(upgraded);
|
||||||
expect(bytes.find("\"schema\":3") != std::string::npos);
|
expect(bytes.find("\"schema\":4") != std::string::npos);
|
||||||
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
||||||
SymbolIndex reread;
|
SymbolIndex reread;
|
||||||
expect(reread.load(upgraded));
|
expect(reread.load(upgraded));
|
||||||
@@ -394,7 +394,7 @@ VOID_TEST(SymbolIndex, generation_restore_persists_the_migrated_schema) {
|
|||||||
expect(restored->migrated);
|
expect(restored->migrated);
|
||||||
expect(count(loaded.find({.name = "a"})) == 1);
|
expect(count(loaded.find({.name = "a"})) == 1);
|
||||||
const auto bytes = file_text(root / "snapshot.json");
|
const auto bytes = file_text(root / "snapshot.json");
|
||||||
expect(bytes.find("\"schema\":3") != std::string::npos);
|
expect(bytes.find("\"schema\":4") != std::string::npos);
|
||||||
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
||||||
expect(fs::is_regular_file(root / "snapshot.prev.json"));
|
expect(fs::is_regular_file(root / "snapshot.prev.json"));
|
||||||
SymbolIndex reread;
|
SymbolIndex reread;
|
||||||
@@ -482,7 +482,7 @@ VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) {
|
|||||||
require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)})));
|
require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)})));
|
||||||
require(index.save(path));
|
require(index.save(path));
|
||||||
auto bytes = file_text(path);
|
auto bytes = file_text(path);
|
||||||
const auto schema = bytes.find("\"schema\":3");
|
const auto schema = bytes.find("\"schema\":4");
|
||||||
require(schema != std::string::npos);
|
require(schema != std::string::npos);
|
||||||
bytes.replace(schema, 10, "\"schema\":2");
|
bytes.replace(schema, 10, "\"schema\":2");
|
||||||
put_text(path, bytes);
|
put_text(path, bytes);
|
||||||
@@ -493,7 +493,7 @@ VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) {
|
|||||||
expect(restored->migrated);
|
expect(restored->migrated);
|
||||||
expect(count(loaded.find({.name = "f"})) == 1);
|
expect(count(loaded.find({.name = "f"})) == 1);
|
||||||
require(loaded.save(path));
|
require(loaded.save(path));
|
||||||
expect(file_text(path).find("\"schema\":3") != std::string::npos);
|
expect(file_text(path).find("\"schema\":4") != std::string::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID_TEST(SymbolIndex, rejects_an_oversized_signature) {
|
VOID_TEST(SymbolIndex, rejects_an_oversized_signature) {
|
||||||
@@ -529,3 +529,20 @@ VOID_TEST(SymbolIndex, selector_records_the_previous_generation_name) {
|
|||||||
SymbolIndex rejected;
|
SymbolIndex rejected;
|
||||||
expect(!rejected.restore_generation(root).has_value());
|
expect(!rejected.restore_generation(root).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID_TEST(SymbolIndex, schema_4_rejects_an_unknown_digest_algorithm) {
|
||||||
|
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
|
||||||
|
const auto path = temp.path() / "index.json";
|
||||||
|
SymbolIndex index;
|
||||||
|
require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)})));
|
||||||
|
require(index.save(path));
|
||||||
|
auto bytes = file_text(path);
|
||||||
|
const auto algorithm = bytes.find("\"digestAlgorithm\":\"sha256\"");
|
||||||
|
require(algorithm != std::string::npos);
|
||||||
|
bytes.replace(algorithm, 26, "\"digestAlgorithm\":\"blake3\"");
|
||||||
|
put_text(path, bytes);
|
||||||
|
const auto restored = index.restore(path);
|
||||||
|
require(restored.has_value());
|
||||||
|
expect(restored->status == SymbolIndex::LoadStatus::incompatible);
|
||||||
|
expect(restored->quarantine.has_value());
|
||||||
|
}
|
||||||
Reference in new issue
Block a user