Skip to content

view: fixes from the review of the Fluent Bit upgrade - #111

Merged
edsiper merged 3 commits into
masterfrom
view-review-fixes
Dec 3, 2026
Merged

edsiper merged 3 commits into
masterfrom
view-review-fixes

Conversation

@edsiper

@edsiper edsiper commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the six findings the automated review raised on the CFL code in fluent/fluent-bit#12881. Two are defects in map views, one is a test robustness item, three are documentation.

Code

  • A refused cfl_view_kvlist_load() left the view attached. With a NULL list the call returned -1 but kept the view on the list it was loaded over, so a later commit applied the pending edits to that list. It now leaves the view empty and detached, as the header already promised for a failed load.
  • A variant moved into the list could keep a dangling payload. A variant in the allocator of the list moves in without a copy. If a string or bytes payload in it (at any depth) referenced a key that the same commit renames, or a pair it removes, the commit freed those bytes and a later read used freed memory. The commit now gives the variant its own copy of every payload it references before it moves. A variant in another allocator was already copied in full.

Tests

  • refused_load_detaches: stages a rename, attempts the NULL load, checks the commit fails and the list is unchanged.
  • commit_owns_referenced_payloads: a string, and an array holding a string, bytes and a nested list, all referencing a renamed key or a removed pair; heap and arena. Without the fix it fails under ASan with a heap-use-after-free.
  • kvlist_read and variants no longer dereference a result that a failed check left NULL.

Documentation

  • VIEW.md: a view can be materialized only when its backend has the materialize callback for the source entries that are left.
  • VIEW.md and cfl_view.h: a cleared modified mark records that the edits were written elsewhere. It does not make the source match the view, so after a clear cfl_view_modified() alone must not decide a whole-map copy.
  • CHANGELOG.md: cfl_kvlist_rename_s() compares bytes, while the default fetch ignores case.

Behavior change

A referenced string or bytes payload inside a variant handed to a kvlist view is copied at commit, so the list owns it afterwards. Before, it stayed referenced when the variant and the list shared an allocator.

Testing

  • CFL suite: 36 of 36 pass under ASan and UBSan, and with scripts/agent-verify.sh.
  • Every CFL test binary is clean under Valgrind.
  • Both new cases fail without the fix and pass with it.
  • An allocation-failure sweep over the new copy path (each of the first 64 allocations of the commit failed in turn, then the commit retried) ends with the expected list and no leak under ASan.

cfl_view_kvlist_load() with a NULL list returned -1 and left the view
attached to the list it was loaded over, so a later commit applied the
pending edits to that list. It now leaves the view empty and detached,
like every other failed load.

A variant in the allocator of the list moves into it on commit without
a copy. A string or bytes payload it referenced, at any depth, could
point at a key the same commit renames or at a pair it removes, and
was read after the commit freed it. The commit now gives the variant
its own copy of those payloads before it moves.

The comment of cfl_view_modified_clear() no longer says the view reads
as unmodified: the entries keep their edits and the source does not
match the view.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Two new cases, and the reads in 'kvlist_read' and 'variants' no longer
dereference a result that a failed check left NULL.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
A view can be materialized only when its backend has the callback for
the source entries that are left. A cleared modified mark records that
the edits were written elsewhere; it does not make the source match the
view. The changelog says that cfl_kvlist_rename_s() compares bytes.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
edsiper merged commit 58fbcc5 into master Dec 3, 2026
29 checks passed
@edsiper
edsiper deleted the view-review-fixes branch December 3, 2026 15:39
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