From 675fa82c54b83ef5c6e91e1cf07e3dd46b583032 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Mon, 17 Nov 2025 14:20:27 +0100 Subject: [PATCH] fix(sample_container): truncate file If there is already a file in the filesystem with the same name and it is larger than the new size we are writing, the file size will not be truncated and we will end up with junk after the end of the wasm buffer. Use FS_O_TRUNC, so that the file will always be truncated to the new size. Signed-off-by: Marco Casaroli --- src/samples-mini/zephyr/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samples-mini/zephyr/main.c b/src/samples-mini/zephyr/main.c index 024cf0a4..66800605 100644 --- a/src/samples-mini/zephyr/main.c +++ b/src/samples-mini/zephyr/main.c @@ -83,7 +83,7 @@ void create_sample_container(char *file_name) { int res; fs_file_t_init(&f); - res = fs_open(&f, file_path, FS_O_CREATE | FS_O_RDWR); + res = fs_open(&f, file_path, FS_O_CREATE | FS_O_TRUNC | FS_O_RDWR); fs_write(&f, &wasm_binary, wasm_binary_len); fs_close(&f);