Bug 22429: Infinite loop in patron card printing
authorDavid Cook <dcook@prosentient.com.au>
Mon, 4 Mar 2019 06:43:29 +0000 (17:43 +1100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 26 Mar 2019 06:25:29 +0000 (07:25 +0100)
Text fields in Patron Card Text Layouts can contain regular
expression metacharacters, which - instead of being treated as
literal values - are interpreted and prevent line wrapping. This
causes the process to get stuck in an infinite loop, which keeps
running even after the web server has timed out (at least when
using CGI).

This patch escapes the relevant input from the text field so the
regular expression substitution treats characters as literals
instead of as metacharacters.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 3bd900496690375b2b711743ffaa57371388f687)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 296f6756ab51103d0e104e16cff312d28a8fd165)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d272137c4f764f8a21f02f56c4dba0ad315ec4aa)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

C4/Patroncards/Patroncard.pm

index 559d10d..661a9e8 100644 (file)
@@ -260,7 +260,8 @@ sub draw_text {
                 $line =~ m/^.*(\s.*\s*|\s&|\<.*\>)$/;
                 warn sprintf('Line wrap failed. DEBUG INFO: Data: \'%s\'\n Method: C4::Patroncards->draw_text Additional Information: Line wrap regexp failed. (Please file in this information in a bug report at http://bugs.koha-community.org', $line) and last WRAP_LINES if !$1;
                 $trim = $1 . $trim;
-                $line =~ s/$1//;
+                #Sanitize the input into this regular expression so regex metacharacters are escaped as literal values (https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22429)
+                $line =~ s/\Q$1\E//;
                 $string_width = C4::Creators::PDF->StrWidth($line, $text_attribs->{'font'}, $text_attribs->{'font_size'});
 #                $font_units_width = $m->string_width($line);
 #                $string_width = ($font_units_width * $text_attribs->{'font_size'}) / $units_per_em;