clementgallet / libTAS

GNU/Linux software to (hopefully) give TAS tools to games
GNU General Public License v3.0
494 stars 56 forks source link

Error invoking find for libtcmalloc_minimal.so.4 with spaces in directory name #496

Open ParzivalWolfram opened 2 years ago

ParzivalWolfram commented 2 years ago

On trying to load various games, it appears that an invoke to find has not been properly escaped, as when trying to launch a game that has spaces in its path, errors are thrown as the name is taken as separate search paths. Using The Stanley Parable as an example, the output on game launch is as such:

Try to find the location of libtcmalloc_minimal.so.4 among game files.
find: ‘/home/parzival/fast/SteamLibrary/steamapps/common/The’: No such file or directory
find: ‘Stanley’: No such file or directory
find: ‘Parable’: No such file or directory
-> could not find the library among the game files
/home/parzival/fast/SteamLibrary/steamapps/common/The Stanley Parable/stanley_linux: error while loading shared libraries: libtcmalloc_minimal.so.4: cannot open shared object file: No such file or directory
Attempt 1: Couldn't connect to socket.
Game couldn't start properly.
recv() returns -1 with error Bad file descriptor
The connection to the game was lost. Exiting

In case it matters, i'm using Debian's unstable branch, and the directory is being accessed via a bind mount (/fast -> /home/parzival/fast in this case.)

InfoTeddy commented 2 years ago

Put quotation marks around it, for example the game executable path iirc should be

"/home/parzival/fast/SteamLibrary/steamapps/common/The Stanley Parable/stanley_linux"

It should work (fingers crossed).

I highly doubt the issue is spaces in the path. I've never had issues with spaces in the path.

ParzivalWolfram commented 2 years ago

Put quotation marks around it, for example the game executable path iirc should be "/home/parzival/fast/SteamLibrary/steamapps/common/The Stanley Parable/stanley_linux" It should work (fingers crossed).

I highly doubt the issue is spaces in the path. I've never had issues with spaces in the path.

The errors given would indicate that the issue is with the spaces, as this is similar behavior to when find is given an unquoted and unescaped path with spaces on any given shell.

To answer the deleted comment, as well, I can't launch games when in quotes through the GUI, the Launch button is greyed out when quotes are added.

InfoTeddy commented 2 years ago

The errors given would indicate that the issue is with the spaces, as this is similar behavior to when find is given an unquoted and unescaped path with spaces on any given shell.

Oh, I didn't see that. Then this will have to be a bug that's fixed in libTAS itself, because if you provide the quotes yourself then they will be treated as part of the path.

InfoTeddy commented 2 years ago

Also, since this code path is caused by libTAS needing to find the library among game files instead of in system folders, it might be worth a shot to install libtcmalloc_minimal.so.4 system-wide yourself.

ParzivalWolfram commented 2 years ago

Also, since this code path is caused by libTAS needing to find the library among game files instead of in system folders, it might be worth a shot to install libtcmalloc_minimal.so.4 system-wide yourself.

Is there a full list of libraries it'll do this with, so I can bypass the issue?

InfoTeddy commented 2 years ago

Also, since this code path is caused by libTAS needing to find the library among game files instead of in system folders, it might be worth a shot to install libtcmalloc_minimal.so.4 system-wide yourself.

Is there a full list of libraries it'll do this with, so I can bypass the issue?

It's nothing to do with the library itself, it depends on the libraries that the game uses. My understanding is that libTAS tries to look for the libraries in the system folder first, and then only looks for it through the game files if it can't find them in the system folders. So, you can easily make a full list of libraries yourself, by looking at the libraries in the game folders.

InfoTeddy commented 2 years ago

I'd also like to note that this isn't the only time where user-supplied paths are passed to invoked shell commands and aren't being escaped. For example, this is done earlier in the routine to detect game libraries:

https://github.com/clementgallet/libTAS/blob/0e2259f3612537fc6ea44087f75e2f0b4f513071/src/program/GameThread.cpp#L287-L291

There are several other places in the codebase, if you grep for popen.

InfoTeddy commented 2 years ago

This should probably be fixed by doing what's described in https://github.com/clementgallet/libTAS/issues/333#issuecomment-624338307:

Escape it by replacing ' with '\'' in each element, surrounding them with ', and concatenate them with spaces. This is inefficient, but it's very simple and will always work.

ParzivalWolfram commented 2 years ago

Note that for most shells you can also escape spaces like any other character, which may be a little more efficient.

clementgallet commented 2 years ago

This library search code is meant to ease the users from setting the library path inside File > Executable options. You can set it so you won't have the error instead. I fixed the space issue, but other characters are not escaped, such as '.

ParzivalWolfram commented 2 years ago

This library search code is meant to ease the users from setting the library path inside File > Executable options. You can set it so you won't have the error instead. I fixed the space issue, but other characters are not escaped, such as '.

You may wish to add the ability to have multiple search directories in this case, as Steam usually includes older versions of libraries for older games and the like, but it's often not a full set. Games also sometimes pack in libraries themselves, so in the case of Steam games, the preferred search priority would most likely be the game's libraries, then Steam's, then the system-wide libraries.