You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kit and bindings: fixes from a full AddressSanitizer run - #57
Boundary checks in the C kit, and what a full AddressSanitizer + LeakSanitizer run over the whole project found.
Kit (kit/):
BK_node_add refuses to put a node under its own descendant. That made the tree a cycle, which every walk (layout, drawing, free) followed forever. It returns 0 now, as it already did for a node added to itself.
BK_menubutton_set_items only acts on "menubutton" nodes. On another node it used n->ext as menu data: it overwrote a list's or canvas's own data, and leaked on a node with none. Every caller (Python components, Qt, tkinter, Lua) passes menubuttons, so none of them change.
No stale raster after a render (use-after-free).BK_render left its raster in the kit's global draw state. A host that freed it and then called BK_draw_widget set a clip on freed memory; Lua's test hit this. The draw state now names a raster only while it is drawn into. BUI_kit.h documents that the context keeps its last frame for the eyedropper.
Bindings:
Lua:ctx:render keeps one raster per context, freed with it, instead of a temporary per call. The eyedropper read the freed one, and an incremental render returned only the changes on a blank frame. test_widgets.lua's canvas check passed only because of that blank frame (its canvas was never packed, so it was 0×0); it now packs the canvas and tests what it says.
Python: the Dear ImGui module keeps its types' names, slots and getset tables in process-lifetime storage instead of dropped allocations.
Tests:
anim_test: kills a timeline that kept playing on a dead stack object (a stack-buffer-overflow in the next test).
ime_test: frees its tree.
Rust tests/table.rs: frees the clipboard string it read.
Docs and the changelog cover the user-visible parts.
How was it tested?
AddressSanitizer + LeakSanitizer on Linux (WSL). System libraries' own leaks are suppressed (Mesa/EGL, CUDA, GStreamer and its plugins, fontconfig); the unsuppressed first run showed none of them have BUI frames.
Part
Result
The whole CMake project (kit, GPU, core, Dear ImGui, Python and Lua bindings) via ctest
41 of 43 pass
cargo test -p blenderui -p blenderui-imgui, the kit built with clang's ASan
201 tests pass, doctests included
Go binding (feat/go-bindings, go test -asan, the kit with ASan)
The changes add guards for node insertion and menu-button updates, adjust raster handling in core and Lua rendering, retain generated Python type metadata, and add resource cleanup in tests. API comments, documentation, and the changelog describe these changes.
Changes: Kit API behavior
Layer / File(s)
Summary
Node insertion guard and documentation kit/include/BUI_kit.h, kit/intern/kit_core.c, website/src/content/docs/c/c-api.mdx, docs/c-api.md, CHANGELOG.md
BK_node_add rejects additions that would create a cycle. The header and website documentation describe moving a child with an existing parent and appending at index -1. The Nodes row in docs/c-api.md has no observable content change.
BK_menubutton_set_items returns without changing items when the node is null or is not a menu button. The header comment and changelog describe this behavior.
Render raster state and lifetime kit/include/BUI_kit.h, kit/intern/kit_core.c, CHANGELOG.md
BK_render restores the prior draw raster after rendering. The header and changelog describe how long the context retains its last frame.
Lua context rendering
Layer / File(s)
Summary
Context-owned raster rendering and cleanup bindings/lua/src/bui_internal.h, bindings/lua/src/bui_lua.c, bindings/lua/src/bui_context.c, bindings/lua/tests/test_widgets.lua, CHANGELOG.md
Lua contexts initialize and retain a raster for ctx:render. Rendering returns the raster’s actual dimensions and pixel data. Explicit free and garbage collection use shared context and raster cleanup. The canvas test assigns packed geometry.
Python type metadata
Layer / File(s)
Summary
Generated type metadata storage bindings/python/src/buiimgui_rt.h, CHANGELOG.md
bi_make_type stores generated type names, get/set entries, slots, and type specifications in a static deque.
Test resource cleanup
Layer / File(s)
Summary
Test resource release tests/anim_test.c, tests/ime_test.c, bindings/rust/blenderui/tests/table.rs
The animation test kills its timeline before release. The IME test frees its root node. The Rust clipboard test frees the C-allocated string after copying it.
sequenceDiagram
participant LuaContext
participant Raster
participant BK_render
LuaContext->>Raster: create once and retain
LuaContext->>BK_render: render frame into raster
BK_render-->>LuaContext: return rendered-region count
LuaContext-->>LuaContext: return raster pixels and dimensions
Loading
Suggested reviewers:domain, concprog
Merge Risk: Low · up to c0ad0
The changes harden node insertion, menu-button updates and raster lifetime. A rare nested render from a configure handler could leave the eyedropper sampling an undrawn frame. The risk is low and mostly relates to documented behavior, so it is mergeable with owner awareness.
Security architecture risk: Minimal · up to c0ad0
The inspected changes tighten native API checks and align frame ownership with rendering and cleanup. No introduced or worsened risk materially affecting security, failure containment, or ownership was established. Native callers must still keep the last-rendered raster alive.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The inspected exposure is native memory and frame data within the embedding process. Lua-controlled dimensions reach rendering, and returned pixels are copied into a Lua string. No new privilege transition or cross-service reachability was identified in this path.
Trust Boundaries and Controls
observed — Native hosts remain responsible for the borrowed frame's lifetime; the eyedropper's coordinate checks do not validate object lifetime. Lua now enforces the required lifetime through context-owned storage, while exposing copied pixels rather than the internal raster pointer.
Resilience and Maintainability Implications
observed — The no-damage return still passes through the public wrapper's draw-raster restoration. Lua retries raster creation when its pointer remains null, and explicit release and garbage collection share cleanup that clears the context and raster pointers after freeing them.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names a real part of the changeset: it says the PR contains fixes from an AddressSanitizer run in the kit and bindings. The changes cover BK_node_add cycle rejection, BK_menubutton_set_items…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names a real part of the changeset: it says the PR contains fixes from an AddressSanitizer run in the kit and bindings. The changes cover BK_node_add cycle rejection, BK_menubutton_set_items guarding, BK_render raster lifetime, Lua ctx:render raster ownership, Python type storage, and test cleanup. The title does not name a single primary change, and 'fixes from a full AddressSanitizer run' describes the process more than the code changes. It is still on topic and specific enough for a teammate to see the scope. The title is therefore partially related and passes.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ppmpreetham
changed the title
Kit: refuse tree cycles and menus on non-menu nodes
Kit and bindings: fixes from a full AddressSanitizer run
Nov 22, 2026
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
kit/intern/kit_core.c-2304-2304: 1
2304-2304: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Do not retain an undrawn outer raster.
If a configure handler renders the same context into B, that nested render can clear the dirty state. The outer partial render into A can then return without drawing A, but this assignment retains A. The eyedropper reads A instead of the frame drawn into B. Ensure the outer render redraws A when a nested render consumes its damage.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 43e5db51-efc3-475a-8be2-233ac7e6c4d7
Commits
Reviewing files that changed from the base of the PR and between 32cb3f2 and c0ad04e.
Files selected for processing: 1
kit/intern/kit_core.c
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Boundary checks in the C kit, and what a full AddressSanitizer + LeakSanitizer run over the whole project found.
Kit (
kit/):BK_node_addrefuses to put a node under its own descendant. That made the tree a cycle, which every walk (layout, drawing, free) followed forever. It returns 0 now, as it already did for a node added to itself.BK_menubutton_set_itemsonly acts on"menubutton"nodes. On another node it usedn->extas menu data: it overwrote a list's or canvas's own data, and leaked on a node with none. Every caller (Python components, Qt, tkinter, Lua) passes menubuttons, so none of them change.BK_renderleft its raster in the kit's global draw state. A host that freed it and then calledBK_draw_widgetset a clip on freed memory; Lua's test hit this. The draw state now names a raster only while it is drawn into.BUI_kit.hdocuments that the context keeps its last frame for the eyedropper.Bindings:
ctx:renderkeeps one raster per context, freed with it, instead of a temporary per call. The eyedropper read the freed one, and an incremental render returned only the changes on a blank frame.test_widgets.lua's canvas check passed only because of that blank frame (its canvas was never packed, so it was 0×0); it now packs the canvas and tests what it says.Tests:
anim_test: kills a timeline that kept playing on a dead stack object (a stack-buffer-overflow in the next test).ime_test: frees its tree.tests/table.rs: frees the clipboard string it read.Docs and the changelog cover the user-visible parts.
How was it tested?
AddressSanitizer + LeakSanitizer on Linux (WSL). System libraries' own leaks are suppressed (Mesa/EGL, CUDA, GStreamer and its plugins, fontconfig); the unsuppressed first run showed none of them have BUI frames.
ctestcargo test -p blenderui -p blenderui-imgui, the kit built with clang's ASanfeat/go-bindings,go test -asan, the kit with ASan)The two
ctestfailures:bui_video_test/buipy_video: wall-clock timing checks fail under the load of a parallel ASan run; the test passes 5/5 alone, memory 0/0.bui_video_testalso failed once onmainwithout these changes (32 guarded-alloc blocks left after video) and has not reproduced since.Checklist
CHANGELOG.mdupdated (Unreleased, Fixed)BUI_kit.h,docs/c-api.md, the website's C API page)Summary by CodeRabbit
0without changing the node tree.-1appends it.