Skip to content

fix(sample_container): truncate file#100

Merged
kr-t merged 1 commit intomainfrom
truncate-sample
Nov 18, 2025
Merged

fix(sample_container): truncate file#100
kr-t merged 1 commit intomainfrom
truncate-sample

Conversation

@casaroli
Copy link
Contributor

@casaroli casaroli commented Nov 17, 2025

Description

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.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. set OCRE_INPUT_FILE in CMakeLists.txt to a large wasm file.
  2. Flash, and run -> OK
  3. set OCRE_INPUT_FILE in CMakeLists.txt to a shorter wasm file.
  4. Flash and run -> Error: junk sections after the wasm buffer
  5. fs rm /lfs/ocre/images/hello-world.bin
  6. reboot -> OK

After applying this fix, step 4 should be OK also.

Test Configuration (required):

  • Host OS type, version, and arch: Zephyr 4.3
  • Developer Board make & model: Pimoroni Pico Plus 2W

But the same problem will happen on any platform.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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 <marco.casaroli@gmail.com>
@kr-t kr-t merged commit 734ed5c into main Nov 18, 2025
13 checks passed
@kr-t kr-t deleted the truncate-sample branch November 18, 2025 09:31
PatrickRobbIOL pushed a commit to mgeeIOL/ocre-runtime that referenced this pull request Dec 1, 2025
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 <marco.casaroli@gmail.com>
casaroli added a commit that referenced this pull request Dec 7, 2025
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 <marco.casaroli@gmail.com>
casaroli added a commit that referenced this pull request Jan 7, 2026
This reverts commit 734ed5c.

This commit is kept in the legacy branch.
casaroli added a commit that referenced this pull request Jan 7, 2026
This reverts commit 734ed5c.

This commit is kept in the legacy branch.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli added a commit that referenced this pull request Jan 7, 2026
This reverts commit 734ed5c.

This commit is kept in the legacy branch.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants