Skip to content

Commit 478bb78

Browse files
authored
feat(compression): check metadata schema version (#3022)
Add a check in `micro_allocator.cc` to verify the compression metadata schema version. If the schema version in the metadata is greater than the expected version, log a schema version mismatch error and return a `nullptr`. This prevents potential issues arising from using a newer, unsupported schema version. BUG=part of #2636
1 parent cc09a49 commit 478bb78

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tensorflow/lite/micro/micro_allocator.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,14 @@ const tflite::micro::compression::Metadata* GetCompressionMetadata(
409409
MicroPrintf("Compression: verification failure");
410410
return nullptr;
411411
} else {
412+
tflite::micro::compression::MetadataT schema;
413+
if (compression_metadata->schema_version() > schema.schema_version) {
414+
MicroPrintf("Compression: schema version mismatch (using %d got %d)",
415+
schema.schema_version,
416+
compression_metadata->schema_version());
417+
return nullptr;
418+
}
419+
412420
return compression_metadata;
413421
}
414422
}

0 commit comments

Comments
 (0)