Skip to content

Conversation

@gfgkmn
Copy link

@gfgkmn gfgkmn commented Dec 23, 2025

Fixes a crash that occurs when using the Python API's async_get_contents() method to retrieve terminal content that includes inline images (e.g., displayed via imgcat).

Root Cause

In protoStyleForCharacter:externalAttributes:, the code processes foregroundColorMode and backgroundColorMode to set protobuf enum values. However, for image cells (c.image == 1), the foregroundColor and backgroundColor fields store X/Y image coordinates, not actual colors.

When an image cell happens to have color mode bits that match ColorModeAlternate, and the coordinate values don't correspond to valid ITMAlternateColor enum values, the protobuf library throws an exception during enum validation in GPBSetEnumIvarWithFieldPrivate.

Crash Stack Trace

GPBSetEnumIvarWithFieldPrivate + 116
-[PTYSession protoStyleForCharacter:externalAttributes:] + 280
-[PTYSession stringForLine:length:eaIndex:cppsArray:stylesArray:] + 336
__37-[PTYSession handleGetBufferRequest:]_block_invoke + 172

Fix

Wrap the foreground and background color mode processing in if (!c.image) to skip color interpretation for image cells, since their color fields have different semantics.

Also fixed a pre-existing copy-paste bug where c.foregroundColor was incorrectly used instead of c.backgroundColor when checking the background color alternate mode.

Test Plan

  1. Display an inline image using imgcat
  2. Run a Python script that calls session.async_get_contents() on lines containing the image
  3. Verify iTerm2 no longer crashes and the API returns successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant