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.
This commit is contained in:
yi chen
2026-07-13 08:29:48 +08:00
committed by sonika.rathi
parent a43c51681a
commit 9128ec1a98

View File

@@ -403,7 +403,13 @@ class SpiffsFS(object):
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:
raise RuntimeError("object name '%s' too long" % img_path)
name = img_path