af6b86
diff -up ImageMagick-6.9.10-68/coders/pdf.c.authenticate ImageMagick-6.9.10-68/coders/pdf.c
af6b86
--- ImageMagick-6.9.10-68/coders/pdf.c.authenticate	2019-10-06 00:26:16.000000000 +0200
af6b86
+++ ImageMagick-6.9.10-68/coders/pdf.c	2020-12-18 09:59:52.319382761 +0100
af6b86
@@ -364,6 +364,36 @@ static inline void CleanupPDFInfo(PDFInf
af6b86
     pdf_info->profile=DestroyStringInfo(pdf_info->profile);
af6b86
 }
af6b86
 
af6b86
+static char *SanitizeDelegateString(const char *source)
af6b86
+{
af6b86
+  char
af6b86
+    *sanitize_source;
af6b86
+
af6b86
+  const char
af6b86
+    *q;
af6b86
+
af6b86
+  register char
af6b86
+    *p;
af6b86
+
af6b86
+  static char
af6b86
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
af6b86
+    whitelist[] =
af6b86
+      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
af6b86
+      "$-_.+!;*(),{}|^~[]`\'><#%/?:@&=";
af6b86
+#else
af6b86
+    whitelist[] =
af6b86
+      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
af6b86
+      "$-_.+!;*(),{}|\\^~[]`\"><#%/?:@&=";
af6b86
+#endif
af6b86
+
af6b86
+  sanitize_source=AcquireString(source);
af6b86
+  p=sanitize_source;
af6b86
+  q=sanitize_source+strlen(sanitize_source);
af6b86
+  for (p+=strspn(p,whitelist); p != q; p+=strspn(p,whitelist))
af6b86
+    *p='_';
af6b86
+  return(sanitize_source);
af6b86
+}
af6b86
+
af6b86
 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
af6b86
 {
af6b86
   char
af6b86
@@ -585,11 +615,19 @@ static Image *ReadPDFImage(const ImageIn
af6b86
   if (option != (char *) NULL)
af6b86
     {
af6b86
       char
af6b86
-        passphrase[MaxTextExtent];
af6b86
+        passphrase[MagickPathExtent],
af6b86
+        *sanitize_passphrase;
af6b86
 
af6b86
-      (void) FormatLocaleString(passphrase,MaxTextExtent,
af6b86
-        "\"-sPDFPassword=%s\" ",option);
af6b86
-      (void) ConcatenateMagickString(options,passphrase,MaxTextExtent);
af6b86
+      sanitize_passphrase=SanitizeDelegateString(image_info->authenticate);
af6b86
+#if defined(MAGICKCORE_WINDOWS_SUPPORT)
af6b86
+      (void) FormatLocaleString(passphrase,MagickPathExtent,
af6b86
+        "\"-sPDFPassword=%s\" ",sanitize_passphrase);
af6b86
+#else
af6b86
+      (void) FormatLocaleString(passphrase,MagickPathExtent,
af6b86
+        "'-sPDFPassword=%s' ",sanitize_passphrase);
af6b86
+#endif
af6b86
+      sanitize_passphrase=DestroyString(sanitize_passphrase);
af6b86
+      (void) ConcatenateMagickString(options,passphrase,MagickPathExtent);
af6b86
     }
af6b86
   read_info=CloneImageInfo(image_info);
af6b86
   *read_info->magick='\0';
af6b86
diff -up ImageMagick-6.9.10-68/config/delegates.xml.in.authenticate ImageMagick-6.9.10-68/config/delegates.xml.in
af6b86
--- ImageMagick-6.9.10-68/config/delegates.xml.in.authenticate	2019-10-06 00:26:16.000000000 +0200
af6b86
+++ ImageMagick-6.9.10-68/config/delegates.xml.in	2020-12-18 10:02:24.491442232 +0100
af6b86
@@ -90,8 +90,8 @@
af6b86
   <delegate decode="pcl:cmyk" stealth="True" command=""@PCLDelegate@" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@PCLCMYKDevice@" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s""/>
af6b86
   <delegate decode="pcl:color" stealth="True" command=""@PCLDelegate@" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@PCLColorDevice@" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s""/>
af6b86
   <delegate decode="pcl:mono" stealth="True" command=""@PCLDelegate@" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@PCLMonoDevice@" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s""/>
af6b86
-  <delegate decode="pdf" encode="eps" mode="bi" command=""@PSDelegate@" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sPDFPassword="%a" "-sDEVICE=@GSEPSDevice@" "-sOutputFile=%o" "-f%i""/>
af6b86
-  <delegate decode="pdf" encode="ps" mode="bi" command=""@PSDelegate@" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@GSPSDevice@" -sPDFPassword="%a" "-sOutputFile=%o" "-f%i""/>
af6b86
+  <delegate decode="pdf" encode="eps" mode="bi" command=""@PSDelegate@" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@GSEPSDevice@" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/>
af6b86
+  <delegate decode="pdf" encode="ps" mode="bi" command=""@PSDelegate@" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=@GSPSDevice@" "-sPDFPassword=%a" "-sOutputFile=%o" "-f%i""/>
af6b86
   <delegate decode="pnm" encode="trace" command=""@TraceEncodeDelegate@" --svg --output "%o" "%i""/>
af6b86
   <delegate decode="png" encode="webp" command=""@WebPEncodeDelegate@" -quiet %Q "%i" -o "%o""/>
af6b86
   <delegate decode="pnm" encode="ilbm" mode="encode" command=""@ILBMEncodeDelegate@" -24if "%i" > "%o""/>