Skip to content

metadata: add fixes for metadata handling #111

Merged
edsiper merged 5 commits intomasterfrom
metadata-update-fixes
Nov 3, 2025
Merged

metadata: add fixes for metadata handling #111
edsiper merged 5 commits intomasterfrom
metadata-update-fixes

Conversation

@edsiper
Copy link
Copy Markdown
Member

@edsiper edsiper commented Nov 3, 2025

No description provided.

Fix critical bug in cio_file_write_metadata() where memmove() was using
metadata size instead of content data size when moving content after
metadata expansion. This caused data corruption when metadata size
differed from content size.

Also fix available space calculation to properly account for header and
metadata when determining if file resize is needed.

Fixes issue where updating metadata after writing content data would
corrupt the content when metadata grew larger.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Add comprehensive tests to validate that updating metadata after
writing content data correctly preserves both metadata and content
integrity. The tests specifically cover the scenario where metadata
grows and requires content data to be moved.

Tests include:

 - Single metadata update with content data
 - Multiple metadata updates with varying sizes
 - Validation after chunk down/up cycles

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The resize check in cio_file_write_metadata calculated:

  content_av = alloc_size - CIO_FILE_HEADER_MIN - size

When writing large metadata to a chunk with small initial allocation,
this subtraction could underflow (wrap to huge unsigned value), causing
the resize check to be skipped and leading to out-of-bounds writes.

Fixed by checking if resize is needed before any subtraction:

  if (alloc_size < CIO_FILE_HEADER_MIN + size + data_size)

Also added a regression test in tests/fs.c to verify the fix.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
Copy link
Copy Markdown
Member Author

edsiper commented Nov 3, 2025

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@edsiper edsiper merged commit 56e4b0b into master Nov 3, 2025
7 checks passed
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.

1 participant