Control: tags -1 patch

Please find a patch attached that fixes the issue for me.
Description: Fix nondeterministic thumbnail creation with relative score paths
 When a score is opened, denemo chdir()s into the file's directory while
 keeping Denemo.project->filename as the possibly-relative path given on
 the command line (src/export/file.c). create_thumbnail() later stats that
 stale relative path, which fails. The struct stat is left uninitialized
 in that case, so the freshness check compares the thumbnail mtime against
 stack garbage and may silently skip thumbnail generation (only reported
 via g_debug, which denemo's log handler discards in release builds).
 .
 Initialize the stat buffer and only skip regeneration when both mtimes
 are genuinely known. This makes autopkgtest's testThumbnailer test
 deterministic on all architectures.
Author: Bastian Germann <[email protected]>
Bug-Debian: https://bugs.debian.org/1127039
Forwarded: no
Last-Update: 2026-08-23
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/printview/printview.c
+++ b/src/printview/printview.c
@@ -5,6 +5,7 @@
 #endif
 #include <errno.h>
 #include <math.h>
+#include <string.h>
 #include <glib/gstdio.h>
 
 #include "printview/printview.h"
@@ -925,15 +926,21 @@
     }
 
   //check if thumbnail is newer than file
+  //Note: Denemo.project->filename may be a relative path and the working directory may have
+  //changed since the score was opened (see chdir in src/export/file.c), so the stat can fail.
+  //Only skip regeneration when both mtimes are genuinely known.
   struct stat thebuf;
-  g_stat (Denemo.project->filename->str, &thebuf);
-  unsigned mtime = thebuf.st_mtime;
-
-  thebuf.st_mtime = 0;
-  g_stat (thumbpathN, &thebuf);
-  unsigned mtime_thumb = thebuf.st_mtime;
+  memset (&thebuf, 0, sizeof (thebuf));
+  gboolean have_file_mtime = (g_stat (Denemo.project->filename->str, &thebuf) == 0);
+  unsigned mtime = have_file_mtime ? thebuf.st_mtime : 0;
+  if (!have_file_mtime)
+    g_message ("Could not stat %s to check thumbnail freshness - regenerating", Denemo.project->filename->str);
+
+  memset (&thebuf, 0, sizeof (thebuf));
+  gboolean have_thumb_mtime = (g_stat (thumbpathN, &thebuf) == 0);
+  unsigned mtime_thumb = have_thumb_mtime ? thebuf.st_mtime : 0;
 
-  if (mtime_thumb >= mtime)
+  if (have_file_mtime && have_thumb_mtime && mtime_thumb >= mtime)
     {
       g_debug ("Do not update thumbnail %s", thumbpathN);
       return FALSE;

Reply via email to