Skip to content

fix(python-renderer): IndexError on multi-byte buffers#102

Open
shiroimon wants to merge 1 commit into
TaDaa:masterfrom
shiroimon:fix/multibyte-indexerror-process-syn
Open

fix(python-renderer): IndexError on multi-byte buffers#102
shiroimon wants to merge 1 commit into
TaDaa:masterfrom
shiroimon:fix/multibyte-indexerror-process-syn

Conversation

@shiroimon
Copy link
Copy Markdown

Summary

Fix IndexError in process_syn when fading buffers with multi-byte characters
(Japanese, devicons, emoji) on the Python 3 / IS_V3 path. The error fires within
seconds of switching windows and, after 3 occurrences, auto-disables vimade.

01-indexerror-tick 02-indexerror-deferred-tick

Root cause

On IS_V3, text and text_ln are computed in UTF-8 bytes (namespace.py:278-279)
and m_col is clamped to text_ln. But the row entry pushed to to_eval was buf[r] — a Python str whose len() counts characters. Downstream, process_syn sizes the
color grid by character count and indexes into it with m_col - 1 (byte index). Any byte
index past the character count → IndexError.

Visible symptom of the same mismatch — the tail of each multi-byte line stays un-faded:

03-nerdtree-tail-not-faded

Fix

lib/vimade/state/namespace.py:305: store text (the bytes already computed two lines above) instead of buf[r].
Grid sizing and column indices now share the same unit. ASCII buffers are unaffected (byte length == character length).

Repro

Vim 9.x + Python 3, open a buffer with Japanese / devicons, :vsplit, switch windows.


Thanks for maintaining vimade — happy to iterate on this patch if a different approach is preferred.

…yte buffers

When `IS_V3` is true, `text` and `text_ln` are computed in UTF-8 bytes
(see namespace.py:278-279), and `m_col` is bounded by `text_ln`
(byte length). However the row_text appended to `to_eval` was still
the original `buf[r]` (Python str / character length), which causes
`grid[row]` to be sized by character count while `m_col-1`
(byte index) can exceed it.

For buffers containing multi-byte characters (Japanese, devicons,
emoji, etc.), this triggers `IndexError: list index out of range`
in `process_syn`'s `colors[column]` access, which after 3 occurrences
disables vimade entirely.

Storing `text` (the bytes representation already used to compute
`text_ln`) keeps grid sizing and column indices consistent in
byte units, eliminating the IndexError. ASCII buffers are
unaffected since byte length and character length match.

Repro:
  - Vim 9.x with Python 3 (IS_V3 path)
  - Open a buffer containing Japanese / devicons
  - :vsplit and move between windows
  - vimade fails with IndexError after a few ticks
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