From e628a207acc0d24751b74a4ea09dff137aa9c734 Mon Sep 17 00:00:00 2001 From: yi chen <94xhn1@gmail.com> Date: Mon, 13 Jul 2026 08:29:48 +0800 Subject: [PATCH 1/2] fix(spiffs): fix off-by-one in spiffsgen.py obj name length check SpiffsFS.create_file() rejected names only when strictly longer than obj_name_len, but CONFIG_SPIFFS_OBJ_NAME_LEN's documented semantics (see components/spiffs/Kconfig) are that the length includes the zero-termination character, so the maximum number of actual name characters is obj_name_len - 1. With the old check, a name exactly obj_name_len characters long was accepted. SpiffsObjIndexPage.to_binary() then computes the NUL padding after the name as (obj_name_len - len(name)), which is 0 in that case, so the generated image's fixed-size name field ends up with no NUL terminator anywhere in its reserved region. Fix the boundary so the generator enforces the same maximum length that the Kconfig help text documents. --- components/spiffs/spiffsgen.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py index 690c40cd220..b4dfc61f3cf 100755 --- a/components/spiffs/spiffsgen.py +++ b/components/spiffs/spiffsgen.py @@ -423,7 +423,13 @@ class SpiffsFS: return self.remaining_blocks <= 0 def create_file(self, img_path, file_path): # type: (str, str) -> None - if len(img_path) > self.build_config.obj_name_len: + # obj_name_len includes the zero-termination character (see Kconfig + # help for CONFIG_SPIFFS_OBJ_NAME_LEN), so the maximum number of + # actual name characters is obj_name_len - 1. Without the "- 1" here, + # a name exactly obj_name_len characters long is wrongly accepted and + # SpiffsObjIndexPage.to_binary() ends up writing zero NUL bytes into + # the reserved name field. + if len(img_path) > self.build_config.obj_name_len - 1: log.die(f"object name '{img_path}' too long") name = img_path From 7fe0c2392f2cb33783bb811f82b0fbbc24b6d886 Mon Sep 17 00:00:00 2001 From: "sonika.rathi" Date: Thu, 16 Jul 2026 09:52:08 +0200 Subject: [PATCH 2/2] fix(spiffs): shorten obj_name_len guard comment --- components/spiffs/spiffsgen.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py index b4dfc61f3cf..c714d86ca06 100755 --- a/components/spiffs/spiffsgen.py +++ b/components/spiffs/spiffsgen.py @@ -423,12 +423,7 @@ class SpiffsFS: return self.remaining_blocks <= 0 def create_file(self, img_path, file_path): # type: (str, str) -> None - # obj_name_len includes the zero-termination character (see Kconfig - # help for CONFIG_SPIFFS_OBJ_NAME_LEN), so the maximum number of - # actual name characters is obj_name_len - 1. Without the "- 1" here, - # a name exactly obj_name_len characters long is wrongly accepted and - # SpiffsObjIndexPage.to_binary() ends up writing zero NUL bytes into - # the reserved name field. + # obj_name_len includes NUL (CONFIG_SPIFFS_OBJ_NAME_LEN); max chars is obj_name_len - 1. if len(img_path) > self.build_config.obj_name_len - 1: log.die(f"object name '{img_path}' too long")