Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#8122·HandBrake

Flatpak: Temp Directory preference can store a transient portal path, silently breaking every preview

Author: louquillioCreated Sep 25, 2026Updated Sep 25, 2026

AI-assisted issue — drafted by Hermes Agent (Nous Research) on behalf of @louquillio.

Summary

On the Flatpak build, the Preferences "Temp Directory" setting can end up holding a transient document-portal path (/run/user/<uid>/doc/<hash>/...). That path stops existing once the portal grant ends, and libhb then keeps using the dead path for the life of every later process. The result is permanent, silent breakage of every preview: no thumbnails, a black preview pane, and no error shown. Encoding is unaffected, so the app looks otherwise healthy.

The value stored in my preferences was:

json
"CustomTmpEnable": true,
"CustomTmpDir": "/run/user/1000/doc/5d8ca6e4/tmp"

/run/user/1000/doc/5d8ca6e4 no longer exists, and there is no entry for it in the portal's document store either, so I cannot say which real directory it once stood for.

Environment

Standard header from the affected machine:

HandBrake 1.11.2 (2011111100)
OS: GNOME 49 (Flatpak runtime)
Kernel: Linux 7.0.0-34-generic (x86_64)
CPU: 13th Gen Intel(R) Core(TM) i9-13900HK x 20
Install Dir: /app/bin
Config Dir:  /home/louquillio/.var/app/fr.handbrake.ghb/config/ghb

Relevant to this report: Flatpak 1.14.10; app fr.handbrake.ghb branch stable, commit 2565549..., on org.gnome.Platform/x86_64/49; xdg-desktop-portal 1.18.4 with the gnome 46.2, gtk 1.15.1 and xapp 1.0.4 backends; Wayland session, Zorin OS 18.1 (Ubuntu 24.04 base). The Cannot load libnvidia-encode.so.1, vcn and qsv lines in that header are expected in this build (no hardware encoders exposed) and unrelated to this report.

Steps to reproduce

  1. In the Flatpak build, Preferences -> Temp Directory -> choose a folder.
  2. Let the portal grant lapse (log out, reboot, or restart the portal).
  3. Open HandBrake and load a source. Thumbnails never appear, the preview pane is black, and nothing is reported. The Activity Log holds the errors.

Errors (reproduced headlessly inside the Flatpak sandbox)

The GUI's Activity Log shows these same lines for this state; the block below comes from a reproduction of the identical code path, so the values are exact rather than transcribed.

ERROR: Failed to create a temporary directory at /run/user/1000/doc/5d8ca6e4/tmp/handbrake-XXXXXX
ERROR: hb_save_preview: Failed to open /run/user/1000/doc/5d8ca6e4/tmp/handbrake-XXXXXX/0_1_0.jpg (reason: No such file or directory)
... one line per preview ...

Mechanism (verified against the 1.11.2 tag)

  1. gtk/src/application.c:827 — the CustomTmpEnable / CustomTmpDir preferences are passed straight to hb_set_temporary_directory().
  2. libhb/ports.c:757 — mkdtemp("%s/handbrake-XXXXXX") fails, the failure is logged, and the path is kept anyway ("We still use the path even if directory creation fails"). The name is resolved once per process through pthread_once, so there is no later recovery.
  3. libhb/hb.c:536 and hb.c:672 — preview images are written into that directory (<instance>_<title>_<preview>.jpg) and read back from it.
  4. libhb/hb.c:815 — hb_get_preview() opens by reading that file back; a failed read returns NULL.
  5. gtk/src/hb-backend.c:4901 — on NULL, the GUI builds a zeroed 854x480 pixbuf and returns it as the preview image. That is the black pane, and it is why nothing is reported. (Real previews are written at source resolution, so a black 854x480 pane is the tell.)
  6. The live preview segment goes to the same directory (%s/live%02d, ghb_get_tmp_dir() -> hb_get_temporary_directory()), so pressing Play has nothing to show either.
  7. Only temp-file users are affected: previews, the preview image cache, and multi-pass statistics. A single-pass encode never touches the directory, which is why encodes keep working while previews look completely broken.

Why this is not the existing reports

#7190 and #7211 show the same error signatures on macOS, but the reply there was that HandBrake only asks the operating system for a temp location (@galad87: "if the operating system is not allowing to write at the path it provided, there isn't much we can do"). Here the OS is not involved: the failing path is one HandBrake itself captured through the document portal and persisted in its own preferences. It therefore fails deterministically, survives updates and reinstalls, and cannot be corrected from the UI. #6994 (fixed by #6999) shows this same function being patched for a different path-handling defect.

Reproduced headlessly

HandBrakeCLI links the same libhb and honours TMPDIR, so the failure reproduces without the GUI:

bash
flatpak run --command=sh fr.handbrake.ghb -c '
  echo "--- control ---"
  TMPDIR=/tmp HandBrakeCLI --scan --previews 10:1 -i <source> 2>&1 | grep -iE "temporar|preview|error"
  echo "--- stored preference ---"
  TMPDIR=/run/user/1000/doc/5d8ca6e4/tmp HandBrakeCLI --scan --previews 10:1 -i <source> 2>&1 | grep -iE "temporar|preview|error"'

The control run is clean. The second emits the directory-creation failure plus one hb_save_preview: Failed to open ... for each preview. Pointing CustomTmpDir at a real directory restores the cache: the GUI's own scan then writes all 15 preview JPEGs again.

Suggested fixes

Any one of these removes the silent, permanent failure:

  1. Do not persist a portal path for Temp Directory. A portal view is read-only and can never serve as a temp directory, so either resolve the selection to its real path or refuse it with an explanation when it is chosen. This matters more as the Flatpak moves toward portal-only access (#5283, raised again in #7373): under that model the setting cannot work as written at all.
  2. Fall back instead of using a dead path. hb_init_temporary_directory already knows creation failed; using $TMPDIR / /tmp in that case turns a permanent breakage into a warning.
  3. Report it in the UI. The Activity Log has the error while the pane silently shows black. Returning a zeroed image from gtk/src/hb-backend.c:4901 is what made a one-line configuration problem invisible for a year.

Workaround for affected users

With HandBrake closed, edit ~/.var/app/fr.handbrake.ghb/config/ghb/preferences.json and either set "CustomTmpEnable" to false, or set "CustomTmpDir" to a real path — plain host paths are reachable because the build ships --filesystem=host. Do not re-pick the folder in Preferences: the chooser stores another portal path. (Users set a custom temp directory because the sandbox's /tmp is memory-backed and too small for multi-pass statistics, see #2053.)

Source: HandBrake/HandBrake

View original on GitHubView discussion on GitHub