Skip to content

IndexError: string index out of range, with a kali shell and some Chinsese characters. #207

@astro-angelfish

Description

@astro-angelfish

I was trying to provide LLM a shell by using pyte, after some actions I got caught by these error:

Traceback (most recent call last):
... i should hide them as they are irrelevant and maybe confidential ...
  File "/app/al1s_terminal_driver/driver.py", line 79, in get_buffer
    return self.pyte_screen.display
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyte/screens.py", line 244, in display
    return ["".join(render(self.buffer[y])) for y in range(self.lines)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyte/screens.py", line 241, in render
    is_wide_char = wcwidth(char[0]) == 2
                           ~~~~^^^
IndexError: string index out of range

Steps to reproduce:

  1. Use paramiko to SSH into a kali server/container
  2. Connect the SSH channel to pyte, with these code:
channel = paramiko_ssh_client.invoke_shell(term='linux', width=width, height=height)
screen = pyte.Screen(width, height)
stream = pyte.ByteStream(screen)

# read from ssh, you may need to run these code below in another thread.
while True:
    data = channel.recv(1)
    stream.feed(data)
  1. Send some Chinese character via channel#send method (in this example: subfinder工具已成功安装。软件包信息显示版本为2.12.0-0kali2,并且系统确认它已是最新版本。安装过程顺利完成。 was the last thing sent before the error)
  2. Invoke screen.dirty.clear() and screen.display, error occurs.

The shell connected was in Kali Linux

I was on pyte==0.8.2. However I checked the source but things mismatches (and seems already fixed). Maybe tag a newer release to pypi?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions