Skip to content

Fix parser crashes on transient null lines and temporary string lifetime#41

Merged
ctapmex merged 1 commit intocolorer:masterfrom
exkrexpexfex:master
Feb 25, 2026
Merged

Fix parser crashes on transient null lines and temporary string lifetime#41
ctapmex merged 1 commit intocolorer:masterfrom
exkrexpexfex:master

Conversation

@exkrexpexfex
Copy link
Contributor

@exkrexpexfex exkrexpexfex commented Feb 8, 2026

This PR addresses a series of ASan-reported crashes in the colorer parser and related string handling when testing quick colored popups creation and destruction in scope of elfmz/far2l#3248

Findings

  • UnicodeString::UnicodeString(int) built a CString from std::to_string(no).c_str() where the std::string temporary died before CString was consumed, causing a stack-use-after-scope read.
  • TextParser::Impl::colorize() threw an exception when LineSource::getLine() returned null, which propagated across threads and left the UI in a bad state.
  • After the null-return fix, the parser could still reuse a stale str pointer on a later pass (because clearLine blocked a fresh getLine()), leading to a null/invalid deref at str->length().

Changes

  • Make the std::to_string() result live long enough in UnicodeString::UnicodeString(int) by storing it in a local std::string before constructing CString.
  • In TextParser::Impl::colorize(), treat null lines as a graceful stop condition instead of throwing; return cleanly.
  • Reset str and clearLine when getLine() returns null to avoid reusing stale pointers on subsequent passes.

Notes

  • These changes target shutdown/transient editor states where lines are unavailable.
  • No behavior change for normal parsing flow; only defensive handling for unavailable lines and invalid lifetimes.

Testing

  • Reproduced crash with ASan before; retested after changes and the issue no longer reproduced.

@ctapmex ctapmex merged commit a846dee into colorer:master Feb 25, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants