#2 Add patch to lock output file for writing
Opened 2 months ago by zbyszek. Modified 2 months ago
rpms/ zbyszek/intltool write-race-fix  into  rawhide

@@ -0,0 +1,46 @@ 

+ From 7355bdbca18c95a2b99cb254434ad2c2248d6747 Mon Sep 17 00:00:00 2001

+ From: Gianfranco Costamagna <locutusofborg@debian.org>

+ Date: Wed, 2 Dec 2020 16:52:53 +0100

+ Subject: [PATCH] [PATCH] Avoid a race where some processes try to use a

+  partial cache

+ 

+ Gbp-Pq: 0001-Avoid-a-race-where-some-processes-try-to-use-a-parti.patch.

+ ---

+  intltool-merge.in | 5 +++++

+  1 file changed, 5 insertions(+)

+ 

+ diff --git a/intltool-merge.in b/intltool-merge.in

+ index 05db7cf930..89923a7da1 100644

+ --- a/intltool-merge.in

+ +++ b/intltool-merge.in

+ @@ -43,6 +43,7 @@ use Getopt::Long;

+  use Text::Wrap;

+  use File::Basename;

+  use Encode;

+ +use Fcntl qw(:flock);

+  

+  my $must_end_tag      = -1;

+  my $last_depth        = -1;

+ @@ -392,11 +393,14 @@ sub load_cache

+  

+  sub get_cached_translation_database

+  {

+ +    open(my $lockfh, ">", "$cache_file.lock") or die $!;

+ +    flock($lockfh, LOCK_EX) or die "Could not lock '$cache_file.lock' - $!";

+      my $cache_file_age = -M $cache_file;

+      if (defined $cache_file_age) 

+      {

+          if ($cache_file_age <= &get_newest_po_age) 

+          {

+ +            close($lockfh);

+              &load_cache;

+              return;

+          }

+ @@ -404,6 +408,7 @@ sub get_cached_translation_database

+      }

+  

+      &create_cache;

+ +    close($lockfh);

+  }

+  

+  sub add_translation

file modified
+8 -5
@@ -1,7 +1,7 @@ 

  Name: intltool

  Summary: Utility for internationalizing various kinds of data files

  Version: 0.51.0

- Release: 26%{?dist}

+ Release: 27%{?dist}

  License: GPL-2.0-or-later WITH Autoconf-exception-generic

  #VCS: bzr:https://code.edge.launchpad.net/~intltool/intltool/trunk

  Source: https://edge.launchpad.net/intltool/trunk/%{version}/+download/intltool-%{version}.tar.gz
@@ -31,6 +31,9 @@ 

  Patch2: intltool-merge-Create-cache-file-atomically.patch

  # https://bugzilla.redhat.com/show_bug.cgi?id=1318674

  Patch3: intltool_distcheck-fix.patch

+ # https://bugzilla.redhat.com/show_bug.cgi?id=2268342

+ # https://bugs.launchpad.net/intltool/+bug/1687644

+ Patch4: 0001-PATCH-Avoid-a-race-where-some-processes-try-to-use-a.patch

  

  %description

  This tool automatically extracts translatable strings from oaf, glade,
@@ -38,10 +41,7 @@ 

  them in the po files.

  

  %prep

- %setup -q

- %patch 1 -p1

- %patch 2 -p1

- %patch 3 -p1

+ %autosetup -p1

  

  %build

  %configure
@@ -69,6 +69,9 @@ 

  %{_mandir}/man8/intltool*.8*

  

  %changelog

+ * Thu Mar  7 2024 Zbigniew Jedrzejewski-Szmek <zbyszek@in.waw.pl> - 0.51.0-27

+ - Add patch to lock output files for reading and writing (rhbz#2268342)

+ 

  * Wed Jan 24 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.51.0-26

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

  

The previous patch that we had, to use a temporary file, is useful:
it prevents the situation where a half-written file is present on disk under the
name that the readers expect. For example, this solves the scenario where the
write is interrupted, and then the build process is restarted and something
reads the partially written file. This could happen when using intltool-merge
during development.

Nevertheless, the existing patch doesn't actually solve the problem of
concurrent writes: the name of the temporary file is fixed, so if two writers
attempt to write the file, they may open the same temporary file and then
finally rename the temporary file to destination. Readers will then read a
corrupted file. This happens in
https://bugzilla.redhat.com/show_bug.cgi?id=2268342, where we get a message that
indicates the cache file is corrupted ("odd number of elements"), and a desktop
file with some missing translations is written.

Patch was verified by rebuilding xfce4-terminal 10 times with an inserted check
that the two desktop files contain the expected number of elements.

The patch was written by Bernhard Wiedemann and is available in the intltool
repo on launchpad (but misattributed).