Skip to content

Crash (abort) right-clicking a data grid cell with long non-ASCII content (Lazarus / macOS Cocoa) #2510

Description

@twinn1013

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

  1. Open a table or run a query so a grid is shown.
  2. Focus a cell whose value is multi-byte text longer than ~100 bytes (e.g. a long Korean/Chinese/Japanese string).
  3. Right-click the cell to open the context menu (the quick-filter menu).
  4. 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_throwabort().

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).

Metadata

Metadata

Assignees

Labels

bugDefective behaviour in HeidiSQLmacosAffects the macOS app bundle

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions