Environment
- HeidiSQL 12.18, Lazarus branch (Cocoa widgetset)
- macOS (Apple Silicon, arm64)
Summary
Right-clicking a data grid cell whose value is long, non-ASCII text (e.g. CJK) aborts the application immediately (SIGABRT, Apple crash reporter). Windows is unaffected.
Steps to reproduce
- Open a table or run a query so a grid is shown.
- Focus a cell whose value is multi-byte text longer than ~100 bytes (e.g. a long Korean/Chinese/Japanese string).
- Right-click the cell to open the context menu (the quick-filter menu).
- The app aborts.
Root cause
The quick-filter menu captions are built with StrEllipsis(Act.Hint, 100). StrEllipsis truncates by byte count (SetLength/Copy), so it can cut in the middle of a multi-byte UTF-8 character and produce invalid UTF-8. On the Cocoa widgetset, the conversion to NSString then yields a nil string (CFStringCreateWithCString fails), and -[NSMenuItem initWithTitle:] asserts that the title is non-nil → objc_exception_throw → abort().
Crash stack (Cocoa build):
-[NSMenuItem initWithTitle:action:keyEquivalent:] <- title == nil -> NSAssertion -> abort()
CocoaMenus.LCLMenuItemInit
TCocoaWSMenuItem.CreateHandle
TMenuItem.CreateHandle / CheckChildrenHandles
TPopupMenu.Popup
TControl.WMContextMenu (TBaseVirtualTree)
-[TCocoaCustomControl rightMouseUp:]
Windows/Delphi is unaffected: there String is UTF-16, so SetLength cuts on code-unit boundaries and the Win32 menu API tolerates the result.
Proposed fix
Make StrEllipsis cut on UTF-8 codepoint boundaries using UTF8Length/UTF8Copy (LazUTF8, already in the unit's uses clause).
The patch is attached in a comment below. The repository restricts opening pull requests to collaborators, so I cannot open a PR; the change is also pushed to twinn1013/HeidiSQL:fix-menu-utf8-truncation-crash (based on lazarus).
Environment
Summary
Right-clicking a data grid cell whose value is long, non-ASCII text (e.g. CJK) aborts the application immediately (SIGABRT, Apple crash reporter). Windows is unaffected.
Steps to reproduce
Root cause
The quick-filter menu captions are built with
StrEllipsis(Act.Hint, 100).StrEllipsistruncates by byte count (SetLength/Copy), so it can cut in the middle of a multi-byte UTF-8 character and produce invalid UTF-8. On the Cocoa widgetset, the conversion toNSStringthen yields a nil string (CFStringCreateWithCStringfails), and-[NSMenuItem initWithTitle:]asserts that the title is non-nil →objc_exception_throw→abort().Crash stack (Cocoa build):
Windows/Delphi is unaffected: there
Stringis UTF-16, soSetLengthcuts on code-unit boundaries and the Win32 menu API tolerates the result.Proposed fix
Make
StrEllipsiscut on UTF-8 codepoint boundaries usingUTF8Length/UTF8Copy(LazUTF8, already in the unit'susesclause).The patch is attached in a comment below. The repository restricts opening pull requests to collaborators, so I cannot open a PR; the change is also pushed to
twinn1013/HeidiSQL:fix-menu-utf8-truncation-crash(based onlazarus).