deri pushed a commit to branch master
in repository groff.

commit b8038971a3cc51cd3981af49092dbdb493f76c06
Author: Deri James <d...@chuzzlewit.myzen.co.uk>
AuthorDate: Sat May 25 13:40:21 2024 +0100

    [gropdf] Deal better with invalid destination names.
    
    Bookmark destinations (supplied by -T to .pdfbookmark)
    are "Name Objects" in pdf terms, as such they are limited
    to characters in the range 33 (!) to 126 (~). Characters
    outside this range must be coded as a # followed by the
    2 digit hex number. So a space character should be '#20'.
    
    Gropdf produces pdfs which conform to this rule, but the
    pdf parser (used to import pdfs for pdfpic) expects only
    valid syntax. To convert pdfmark input to a pdf object
    gropdf used this inbuilt parser.
    
    The .TH macro in an.tmac passes its first parameter as a
    bookmark destination. Normally this is fine, since the
    convention is that this will be the name of the program
    the man page is documenting. The problem in this case
    is the line:-
    
    .TH "Pamaltsat User Manual" 0 "14 September 2018"
        "netpbm documentation"
    
    The first parameter contains spaces, which yields invalid
    syntax when parsed as "/Dest /Pamaltsat User Manual(0)".
    
    * src/devices/gropdf/gropdf: Don't use internal parser
    on "user" supplied input, be a bit more careful.
    
    Fixes: https://savannah.gnu.org/bugs/?65788
    
    Thanks to Bjarni for the report.
---
 ChangeLog                    | 36 ++++++++++++++++++++++++++++++++++++
 src/devices/gropdf/gropdf.pl | 15 ++++++++-------
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e978a25dd..2d68c60e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2024-05-25  Deri James  <d...@chuzzlewit.myzen.co.uk>
+
+       [gropdf] Deal better with invalid destination names.
+
+       Bookmark destinations (supplied by -T to .pdfbookmark)
+       are "Name Objects" in pdf terms, as such they are limited
+       to characters in the range 33 (!) to 126 (~). Characters
+       outside this range must be coded as a # followed by the
+       2 digit hex number. So a space character should be '#20'.
+
+       Gropdf produces pdfs which conform to this rule, but the
+       pdf parser (used to import pdfs for pdfpic) expects only
+       valid syntax. To convert pdfmark input to a pdf object
+       gropdf used this inbuilt parser.
+
+       The .TH macro in an.tmac passes its first parameter as a
+       bookmark destination. Normally this is fine, since the
+       convention is that this will be the name of the program
+       the man page is documenting. The problem in this case
+       is the line:-
+
+       .TH "Pamaltsat User Manual" 0 "14 September 2018"
+           "netpbm documentation"
+
+       The first parameter contains spaces, which yields invalid
+       syntax when parsed as "/Dest /Pamaltsat User Manual(0)".
+
+       * src/devices/gropdf/gropdf: Don't use internal parser
+       on "user" supplied input, be a bit more careful.
+
+       Fixes:-
+
+       https://savannah.gnu.org/bugs/?65788
+
+       Thanks to Bjarni for the report.
+
 2024-05-14  Deri James  <d...@chuzzlewit.myzen.co.uk>
 
        [gropdf] Problem if mixed fonts have different lenIV.
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index 30a8de868..df645c4e0 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -1465,11 +1465,12 @@ sub do_x
                        $cat->{$k}=$docview->{$k} if !exists($cat->{$k});
                    }
                }
-               elsif ($pdfmark=~m/(.+) \/DEST\s*$/)
+               elsif ($pdfmark=~m/\/Dest (\/.+?)( \/View .+) \/DEST\s*$/)
                {
-                   my @xwds=split(' ',"<< $1 >>");
+                   my (@d)=($1,$2);
+                   my @xwds=split(' ',"<< $d[1] >>");
                    my $dest=ParsePDFValue(\@xwds);
-                   $dest->{Dest}=UTFName($dest->{Dest});
+                   $dest->{Dest}=UTFName($d[0]);
                    $dest->{View}->[1]=GraphY($dest->{View}->[1]*-1);
                    unshift(@{$dest->{View}},"$cpageno 0 R");
 
@@ -1504,14 +1505,14 @@ sub do_x
                    my $t=$1;
                    $t=~s/\\\) /\\\\\) /g;
                    $t=~s/\\e/\\\\/g;
-                   $t=~m/(^.*\/Title \()(.*)(\).*)/;
-                   my ($pre,$title,$post)=($1,$2,$3);
+                   $t=~m/^\/Dest (.+?) \/Title \((.*)(\).*)/;
+                   my ($d,$title,$post)=($1,$2,$3);
                    $title=utf16($title);
 
                    $title="\\134" if $title eq "\\";
-                   my @xwds=split(' ',"<< $pre$title$post >>");
+                   my @xwds=split(' ',"<< \/Title ($title$post >>");
                    my $out=ParsePDFValue(\@xwds);
-                   $out->{Dest}=UTFName($out->{Dest});
+                   $out->{Dest}=UTFName($d);
 
                    my $this=[$out,[]];
 

_______________________________________________
Groff-commit mailing list
Groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to