8

Recently I had a bunch of my own scripts for the thumbnails in Nautilus: WebP previews, sound waveforms, office documents and so on.

Seems like either I’m doing something wrong (thumbnail generation behavior changed), or custom thumbnailes don’t work in latest GNOME at all, even my previous scripts, which worked smoothly on previous versions of Ubuntu.

I’ve done some research, tried to run a simple script (see below) and it didn’t work out.

My test thumbnailer in /usr/share/thumbnailers/z.thumbnailer:

[Thumbnailer Entry]
Exec=/home/maximal/thumb.sh %s %i %u %o
MimeType=image/webp;image/x-webp

Where /home/maximal/thumb.sh is:

#!/bin/bash
echo $0 >> /home/maximal/thumb.log
echo $1 >> /home/maximal/thumb.log
echo $2 >> /home/maximal/thumb.log
echo $3 >> /home/maximal/thumb.log
echo $4 >> /home/maximal/thumb.log

Then, when I remove thumbnail cache rm -rf ~/.cache/thumbnails and restart Nautilus nautilus -q, my log file doesn’t contain anything and ~/.cache/thumbnails/fail/gnome-thumbnail-factory contains all the failed thumbs (looks like corrupted/empty PNGs):

Failed thumbnail file

So, apparently, Nautilus even didn’t try to execute my thumbnailer script. When I try to run thumb command itself, it works perfectly. For example convert through cwebp|dwebp package:

convert -thumbnail 256x256 file.webp png:file.webp.png

When I wrap this command to a thumbnailer, it looks like it wasn’t even requested to run by Nautilus.

[Thumbnailer Entry]
Exec=convert -thumbnail %sx%s %i png:%o
MimeType=image/webp;image/x-webp;

Exactly the same situation occurs with other my thumbnailers: audio waveforms, office documents, photoshop files and so on.

Could anyone help?

Rmano
  • 31,947
  • Added 18.04 because the hardening causing this has been backported, see https://bugs.launchpad.net/ubuntu/+source/gnome-desktop3/+bug/1795668 – Rmano Dec 14 '18 at 09:33
  • Trying to study https://github.com/GNOME/gnome-desktop/blob/master/libgnome-desktop/gnome-desktop-thumbnail-script.c – Rmano Dec 16 '18 at 11:06
  • I have opened a bug: https://bugs.launchpad.net/ubuntu/+source/gnome-desktop3/+bug/1808702 – Rmano Dec 16 '18 at 16:47
  • sasha-maximal, @jacek-kluza, marking the aforementioned bug with "affect me also" will confirm it and attract attention by the developers... – Rmano Dec 18 '18 at 15:48

3 Answers3

7

I'm using 18.04, but after 2018.11.28 update I had same issue. It is caused by sandboxing thumbnailers with bubblewrap (it cost me 2 days of research!!!).

So I downgraded gnome-desktop3-data, gir1.2-gnomedesktop-3.0, libgnome-desktop-3-17 (not sure if all 3 needed) and then removed bubblewrap.

It's a dirty hack and it weakens the security, but I don't care...

Maybe it will be not so easy on 18.10.

I hope somebody can write better solution...

  • 2
    WOW! You did a great research. I’ve spent a number of days, but didn’t figured the problem out. – Sasha MaximAL Dec 07 '18 at 06:55
  • 1
    This is caused by https://bugs.launchpad.net/ubuntu/+source/gnome-desktop3/+bug/1795668 . I have asked for a correct fix there, let's see... it's probably a matter of understanding how to write safe thumbnailers. – Rmano Dec 14 '18 at 09:32
7

I've gone thru the same trouble with some of my external thumbnailers.

After some researches, I realised that bubblewarp call fails under Ubuntu and Debian based distros because of --symlink option on /bin and /sbin. In fact under these distros, /bin and /usr/bin are not merged. So, both should be declared with --ro-bind instead of --symlink.

To make bwrap call from Nautilus work under Ubuntu, you need to replace --symlink calls with --ro-bind calls for /bin and /sbin

To solve speed issue with thumbnailers using imagemagick tools, you also need to add a --ro-bind for /etc/alternatives and /var/cache/fontconfig

So, simplest solution is to place a wrapper script under /usr/local/bin/bwrap which will do the job and then call original /usr/bin/bwrap. As /usr/local/bin is before /usr/bin in the PATH, it is transparent for Nautilus.

Wrapper script is available on my Github repo

I've written a small article to explain all into details and to provide wrapper script installation instruction. It has been tested under 18.04 and 18.10

http://bernaerts.dyndns.org/linux/360-ubuntu-nautilus-external-thumbnailer-failure

Hope it helps

  • Interesting. The symlink things should be fixed, see the source code I linked above, but now that I think about it, I am not sure it have percolated down to ubuntu. Will check your suggestion. By the way, for sure you should add a binf for /etc/alternatives too... See my bug report... Thanks! – Rmano Dec 19 '18 at 08:04
  • This is the patch I was mentioning https://gitlab.gnome.org/GNOME/gnome-desktop/commit/259e7e4edb0d9b84fb7cf0847149ff8d42ab9a56 – Rmano Dec 19 '18 at 08:34
  • Ok: tested and it worked. So the problem is that the patch above has not been added to Ubuntu, yet. I will report this in my bugreport; please chime in if you can. And if you have time, please complete this answer so that it's a bit more informative. It solved my problem though, so I'll grant the bounty. – Rmano Dec 19 '18 at 08:58
  • If you change the last line of your bwrap script to /usr/bin/bwrap --ro-bind /etc/alternatives /etc/alternatives --ro-bind /var/cache/fontconfig /var/cache/fontconfig "${ARR_PARAM[@]}" you solve this problem, the /etc/alternatives one, and the huge font generation slowdown... – Rmano Dec 19 '18 at 09:21
  • Links for the above comment: https://gitlab.gnome.org/GNOME/gnome-desktop/issues/90 and https://gitlab.gnome.org/GNOME/gnome-desktop/issues/92 – Rmano Dec 19 '18 at 09:21
  • I've added both --ro-bind needed by imagemagick in the parameters array initialisation in the bwrap wrapper script. It should solve the problem, but I can't test it. Just let me know if it's ok. – Nicolas Bernaerts Dec 19 '18 at 16:15
  • I've added some more details in the answer. – Nicolas Bernaerts Dec 19 '18 at 17:47
  • Nicolas, tested, it works perfectly. – Rmano Dec 19 '18 at 17:58
  • I installed your script and all thumbnailers (even “internal” ones) now fail (~./cache/thumbnails contains only fail directory). What could be wrong with this? https://i.imgur.com/lhpfx8k.png – Sasha MaximAL Dec 28 '18 at 07:33
  • Hi Sasha, Few days ago, I've added a fix for 32 bits distros. May be it is the source of trouble. I've reverted the script on Github. Could you download it again and see if it woks ? – Nicolas Bernaerts Dec 28 '18 at 08:12
  • Hi there! I installed both versions from your GitHub and they didn’t work. My system is Ubuntu 18.10 ×64 :-( Don’t know where the problem could be. I switched off all the external thumbnailers for now, but internal ones don’t work as well. – Sasha MaximAL Dec 28 '18 at 08:53
  • Hi, I tested today latest GitHub version on up to date 18.04 and it works fine. Make sure to delete $HOME/.cache/thumbnails directory. One interesting thing is that latest Nautilus doesn't use --symlink anymore. Patch with --ro-bind is operational. But --ro-bind for /etc/alternative and /var/cache/fontconfig is still not there. So /usr/local/bin/bwrap wrapper is still needed. Cheers – Nicolas Bernaerts Dec 30 '18 at 00:22
  • Solved! Since I needed PHP in my thumbnailers I should have added [ -d "/etc" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/etc" "/etc" ) after ARR_PARAM=( ) in your wrapper and move my thumbnailer out of my home directory (to /usr/local, for instance). – Sasha MaximAL Feb 04 '19 at 08:08
  • I can confirm that this works. Excellent, thank you. – Mike Nakis Apr 18 '19 at 12:08
  • Please update the link to your article. I believe it's now: http://www.bernaerts-nicolas.fr/linux/74-ubuntu/360-ubuntu-nautilus-external-thumbnailer-failure. Also, it appears that latest Nautilus (3.36.3 on Ubuntu 20.04) has added --ro-bind-try for /var/cache/fontconfig and /etc/alternatives so custom thumbnailers work fine now. – Calico Cat Aug 20 '21 at 09:40
  • Your script is probably still needed for systems that haven't applied these patches, however: non-usr-merge patch, font cache patch, /etc/alternatives patch – Calico Cat Aug 20 '21 at 09:52
0

I'm using 18.04 and I could not get the solution with the bwrap script to work. I have a thumbnailer somewhere in my home path, which works under 16.04. I can solve it in 18.04 by putting this program in /usr/bin.

oscar1919
  • 1,707