impr: Refuse invalid Data Inspector edits and guard against decode crashes - #2904
Open
scottanderson wants to merge 6 commits into
Open
scottanderson wants to merge 6 commits into
scottanderson wants to merge 6 commits into
Conversation
A plain byte vector could not tell "no bytes" from "invalid input". Bad input committed an empty value instead of being refused. Return std::optional instead. Invalid text keeps edit mode open with a red border, checked on every keystroke. Trim the edit buffer to the typed length each frame, so it cannot grow without bound.
A Data Inspector row's display or edit function can throw: a custom inspector runs pattern language code, and a pattern-backed row can decode invalid bytes. The throw crossed ImGui's style/table stacks, leaving them unbalanced. Catch at each site, log, and show "Invalid". The pattern tree's "Copy Value" also calls toString() inside a table, so guard that too.
WerWolv
requested changes
Sep 20, 2026
TextInput::draw() resized its buffer every frame, whatever the user typed. Register ImGuiInputTextFlags_CallbackResize instead, the same pattern ImGuiExt::UpdateStringSizeCallback already uses elsewhere: the callback grows the buffer only when ImGui runs out of room for what was typed. This also drops the frame-by-frame `value = value.c_str()` trim; the callback keeps `value`'s size exact, so nothing grows unbounded to trim in the first place.
The comment called it a guard against pattern language code, but a pattern-backed row never re-enters the runtime here: its value comes from a cache executeInspector() already filled in, a failed formatter surfaces through hasValidFormattedValue() rather than a throw, and a visualizer catches and renders its own failure. The catch backstops a ContentRegistry::DataInspector::add() display function instead, which is arbitrary C++ and can still throw for other reasons.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
A Data Inspector row could not differentiate "no bytes" from "invalid input", so bad input committed an empty value instead of being refused.
A row's display or edit function can also throw: a custom inspector runs pattern language code, and a pattern-backed row can decode invalid bytes. The throw crossed ImGui's style and table stacks, leaving them unbalanced and crashing ImHex.
Implementation
Return
std::optionalfromEditWidget::Widget::Functionandhex::decodeByteString(). Invalid text keeps edit mode open with a red border, checked on every keystroke. Trim the edit buffer to the typed length each frame, so it cannot grow without bound.Catch at each site that can throw, log, and show "Invalid". The pattern tree's "Copy Value" also calls
toString()inside a table, so guard that too.