Skip to content

Commit 44d2094

Browse files
committed
Add model format check for tflite.
1 parent d3ab94e commit 44d2094

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ load(void *tflite_ctx, graph_builder_array *builder, graph_encoding encoding,
136136

137137
uint32_t size = builder->buf[0].size;
138138

139+
if (size < 8) {
140+
NN_ERR_PRINTF("Model too small to be a valid TFLite file.");
141+
return invalid_argument;
142+
}
143+
if (memcmp(tfl_ctx->models[*g].model_pointer + 4, "TFL3", 4) != 0) {
144+
NN_ERR_PRINTF("Model file is not a TFLite FlatBuffer (missing TFL3
145+
identifier).");
146+
return invalid_argument;
147+
}
148+
139149
// Save model
140150
tfl_ctx->models[*g].model_pointer = (char *)wasm_runtime_malloc(size);
141151
if (tfl_ctx->models[*g].model_pointer == NULL) {

0 commit comments

Comments
 (0)