fix(python-renderer): IndexError on multi-byte buffers#102
Open
shiroimon wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
IndexErrorinprocess_synwhen fading buffers with multi-byte characters(Japanese, devicons, emoji) on the Python 3 /
IS_V3path. The error fires withinseconds of switching windows and, after 3 occurrences, auto-disables vimade.
Root cause
On
IS_V3,textandtext_lnare computed in UTF-8 bytes (namespace.py:278-279)and
m_colis clamped totext_ln. But the row entry pushed toto_evalwasbuf[r]— a Pythonstrwhoselen()counts characters. Downstream,process_synsizes thecolor grid by character count and indexes into it with
m_col - 1(byte index). Any byteindex past the character count →
IndexError.Visible symptom of the same mismatch — the tail of each multi-byte line stays un-faded:
Fix
lib/vimade/state/namespace.py:305: storetext(the bytes already computed two lines above) instead ofbuf[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.