Matoking / protontricks

A wrapper that does winetricks things for Proton enabled games, requires Winetricks.
GNU General Public License v3.0
1.62k stars 34 forks source link

[Crash] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 18448: invalid continuation byte #317

Open K1ngfish3r opened 1 month ago

K1ngfish3r commented 1 month ago

Describe the bug A clear and concise description of what the bug is. trying to run protontricks, but crashes immediately after selecting a game

To Reproduce Steps to reproduce the behavior:

  1. Run command flatpak run com.github.Matoking.protontricks --gui
  2. Select game from list
  3. Command fails and error is displayed
    i@clr~ $ flatpak run com.github.Matoking.protontricks --gui
    Traceback (most recent call last):
    File "/app/bin/protontricks", line 8, in <module>
    sys.exit(cli())
             ^^^^^
    File "/app/lib/python3.11/site-packages/protontricks/cli/main.py", line 32, in cli
    main(args)
    File "/app/lib/python3.11/site-packages/protontricks/cli/util.py", line 159, in wrapper
    return cli_func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/app/lib/python3.11/site-packages/protontricks/cli/main.py", line 277, in main
    proton_app = find_proton_app(
                 ^^^^^^^^^^^^^^^^
    File "/app/lib/python3.11/site-packages/protontricks/steam.py", line 848, in find_proton_app
    tool_app = find_steam_compat_tool_app(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/app/lib/python3.11/site-packages/protontricks/steam.py", line 604, in find_steam_compat_tool_app
    content = config_vdf_path.read_text()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.11/pathlib.py", line 1059, in read_text
    return f.read()
           ^^^^^^^^
    File "<frozen codecs>", line 322, in decode
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 18448: invalid continuation byte

Expected behavior A clear and concise description of what you expected to happen. Not crash

System (please complete the following information):

Additional context

If the error happens when trying to run a Protontricks command, run the command again using the -vv flag and copy the output!

For example, if the command that causes the error is protontricks 42 faudio, run protontricks -vv 42 faudio instead and copy the output here.

If the output is very long, consider creating a gist using gist.github.com.

Vibeshibe commented 1 month ago

Similar issue here, running Manjaro Linux:

Traceback (most recent call last):
  File "/home/vibeshibe/.local/bin/protontricks", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/vibeshibe/.local/share/pipx/venvs/protontricks/lib/python3.12/site-packages/protontricks/cli/main.py", line 32, in cli
    main(args)
  File "/home/vibeshibe/.local/share/pipx/venvs/protontricks/lib/python3.12/site-packages/protontricks/cli/util.py", line 159, in wrapper
    return cli_func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vibeshibe/.local/share/pipx/venvs/protontricks/lib/python3.12/site-packages/protontricks/cli/main.py", line 277, in main
    proton_app = find_proton_app(
                 ^^^^^^^^^^^^^^^^
  File "/home/vibeshibe/.local/share/pipx/venvs/protontricks/lib/python3.12/site-packages/protontricks/steam.py", line 848, in find_proton_app
    tool_app = find_steam_compat_tool_app(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vibeshibe/.local/share/pipx/venvs/protontricks/lib/python3.12/site-packages/protontricks/steam.py", line 604, in find_steam_compat_tool_app
    content = config_vdf_path.read_text()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/pathlib.py", line 1028, in read_text
    return f.read()
           ^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 38585-38586: invalid continuation byte

Tried with pipx, flatpack, native...

MerijnHendriks commented 1 month ago

Reproduced on my end too, the selected game doesn't matter

Matoking commented 1 month ago

The ~/.steam/steam/config.vdf seems to contain invalid UTF-8 characters.

If possible, could you try printing the portion of the file that's causing the error? Try running the following command, but replace i = 1234 with the position in the UnicodeDecodeError. For example, in @Vibeshibe's reply it's the byte at position 38585:

python3 -c "i = 1234; from pathlib import Path; print((Path.home() / '.steam/steam/config/config.vdf').read_bytes()[i-200:i+200])"

This should print the section around the file that's causing Protontricks to crash, and hopefully provide better context for what's going wrong. We could probably just work around this by ignoring the faulty characters, but I'd like to be sure.

K1ngfish3r commented 1 month ago

The ~/.steam/steam/config.vdf seems to contain invalid UTF-8 characters.

If possible, could you try printing the portion of the file that's causing the error? Try running the following command, but replace i = 1234 with the position in the UnicodeDecodeError. For example, in @Vibeshibe's reply it's the byte at position 38585:

i@clr~ $ python3 -c "i = 15986; from pathlib import Path; print((Path.home() / '.steam/steam/config/config.vdf').read_bytes()[i-200:i+200])"
b'ftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,\n060000004f04000016d0000000010000,xHg\xdcP,a:b0,b:b1,x:b2,y:b3,back:b6,guide:b8,start:b7,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,leftt'

the error was this UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 15986: invalid continuation byte so I changed 1234 to 15986

DockterTeagle commented 1 month ago

I am having a similair issue I ran that command and here is my output b'8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n030000005e040000000b00000d050000,\xa8\xb2\r,a:b0,b:b1,x:b2,y:b3,back:b6,guide:b8,start:b7,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,paddle1:b11,paddle2:b13,paddle3:b12,paddle' I am on nixos and can procvide more info if needed

GothenTrek commented 1 month ago

I too am receiving this error. This is the output of the command: b'8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,\n050000005e040000130b000009050000,\xedp\x0c,a:b0,b:b1,x:b3,y:b4,back:b10,guide:b12,start:b11,leftstick:b13,rightstick:b14,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,misc1:b15,leftx:a0,lefty:a1,rightx:a2,' I am on endeavour

Matoking commented 1 month ago

Alright, seems like the invalid UTF-8 characters are contained in the SDL_GamepadBind, which might point to a bug in the upstream library. In any case, Protontricks doesn't use that field so we should be able to just skip the errors.

I've pushed a potential fix to config_vdf_parse_fix branch. If you're on pipx, you can use the following command to install it:

pipx install --force git+https://github.com/Matoking/protontricks.git@config_vdf_parse_fix

Could someone verify that this fixes the issue?