texlive[48677] Build/source/texk/dvipdfm-x: Fix papersize special bug

commits+kakuto at tug.org commits+kakuto at tug.org
Sun Sep 16 15:28:50 CEST 2018


Revision: 48677
          http://tug.org/svn/texlive?view=revision&revision=48677
Author:   kakuto
Date:     2018-09-16 15:28:49 +0200 (Sun, 16 Sep 2018)
Log Message:
-----------
Fix papersize special bug intorduced in the previous changes (S. Hirata).

Modified Paths:
--------------
    trunk/Build/source/texk/dvipdfm-x/ChangeLog
    trunk/Build/source/texk/dvipdfm-x/dpxconf.c
    trunk/Build/source/texk/dvipdfm-x/dpxconf.h
    trunk/Build/source/texk/dvipdfm-x/dvi.c
    trunk/Build/source/texk/dvipdfm-x/dvi.h
    trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c
    trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c
    trunk/Build/source/texk/dvipdfm-x/tt_aux.c

Modified: trunk/Build/source/texk/dvipdfm-x/ChangeLog
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/ChangeLog	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/ChangeLog	2018-09-16 13:28:49 UTC (rev 48677)
@@ -1,5 +1,15 @@
 2018-09-16  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
 
+	* dvi.[ch], dvipdfmx.c: Fixed a bug that papersize special does
+	not work. (introduced in the previous change) Command line
+	options other than papersize now take precedence over special
+	command options.
+	* dpxconf.[ch], tt_aux.c: Moved always_embed flag to dpx_conf.
+	* pdfencrypt.c: Fixed a bug that calculation of encryption key
+	was not done properly for RC4 and revision 2-3 AES security.
+
+2018-09-16  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
+
 	* dpxutil.[ch], dvi.[ch], dvipdfmx.c, pdfdoc.[ch], pdfencrypt.[ch],
 	pdffont.[ch], xbb.c: Remove duplicated code. Reorganize
 	initialization process. Use struct for passing options.

Modified: trunk/Build/source/texk/dvipdfm-x/dpxconf.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dpxconf.c	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/dpxconf.c	2018-09-16 13:28:49 UTC (rev 48677)
@@ -30,7 +30,7 @@
 
 #include "dpxconf.h"
 
-struct _dpx_conf dpx_conf = {0, dpx_mode_normal_mode, {0}};
+struct _dpx_conf dpx_conf = {0, dpx_mode_normal_mode, 0, {0}};
 
 #ifndef  HAVE_LIBPAPER
 const struct paper paperspecs[] = {

Modified: trunk/Build/source/texk/dvipdfm-x/dpxconf.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dpxconf.h	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/dpxconf.h	2018-09-16 13:28:49 UTC (rev 48677)
@@ -33,6 +33,7 @@
 extern struct _dpx_conf {
   int            verbose_level;
   enum dpx_mode  compat_mode;
+  int            ignore_font_license;
   struct {
     int keep_cache;
   } file;

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.c	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.c	2018-09-16 13:28:49 UTC (rev 48677)
@@ -2310,8 +2310,7 @@
 }
 
 static int
-scan_special (int has_paper_option, int has_encrypt_option,
-              double *wd, double *ht, double *xo, double *yo, int *lm,
+scan_special (double *wd, double *ht, double *xo, double *yo, int *lm,
               int *majorversion, int *minorversion,
               int *enable_encryption, int *key_bits, int32_t *permission,
               char *opassword, char *upassword,
@@ -2443,10 +2442,8 @@
         RELEASE(kv);
       }
     } else if (ns_pdf && !strcmp(q, "encrypt")) {
-      if (!has_encrypt_option) {
-        *enable_encryption = 1;
-        error = scan_special_encrypt(key_bits, permission, opassword, upassword, &p, endptr);
-      }
+      *enable_encryption = 1;
+      error = scan_special_encrypt(key_bits, permission, opassword, upassword, &p, endptr);
     } else if (ns_dvipdfmx && !strcmp(q, "config")) {
       read_config_special(&p, endptr);
     }
@@ -2453,12 +2450,6 @@
     RELEASE(q);
   }
 
-  /* Recover papersizes specified via command line option */
-  if (has_paper_option) {
-    *wd = width;
-    *ht = height;
-  }
-
   return  error;
 }
 
@@ -2465,7 +2456,6 @@
 
 void
 dvi_scan_specials (int page_no,
-                   int has_paper_option, int has_encrypt_option,
                    double *page_width, double *page_height,
                    double *x_offset, double *y_offset, int *landscape,
                    int *majorversion, int *minorversion,
@@ -2514,8 +2504,7 @@
 #define buf ((char*)(dvi_page_buffer + dvi_page_buf_index))
       if (fread(buf, sizeof(char), size, fp) != size)
         ERROR("Reading DVI file failed!");
-      if (scan_special(has_paper_option, has_encrypt_option,
-                       page_width, page_height, x_offset, y_offset, landscape,
+      if (scan_special(page_width, page_height, x_offset, y_offset, landscape,
                        majorversion, minorversion,
                        do_enc, key_bits, permission, owner_pw, user_pw,
                        buf, size))

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.h	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.h	2018-09-16 13:28:49 UTC (rev 48677)
@@ -69,7 +69,6 @@
 
 extern void  dvi_do_page  (double paper_height, double x_offset, double y_offset);
 extern void  dvi_scan_specials (int page_no,
-                                int has_paper_option, int has_encrypt_option,
 				                double *width, double *height,
                                 double *x_offset, double *y_offset, int *landscape,
                                 int *majorversion, int *minorversion,

Modified: trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2018-09-16 13:28:49 UTC (rev 48677)
@@ -115,20 +115,15 @@
 static double x_offset = 72.0;
 static double y_offset = 72.0;
 int    landscape_mode  = 0;
+static int    translate_origin = 0;
 
-
 /* Command line option takes precedence */
 static int     has_paper_option   = 0;
 static int     has_encrypt_option = 0;
 
-int always_embed = 0; /* always embed fonts, regardless of licensing flags */
-
-int translate_origin = 0;
-
 char *dvi_filename = NULL, *pdf_filename = NULL;
 
-static void
-read_config_file (const char *config);
+static void read_config_file (const char *config);
 
 static void
 set_default_pdf_filename(void)
@@ -470,10 +465,11 @@
 };
 
 static void
-do_early_args (int argc, char *argv[])
+do_args_first_pass (int argc, char *argv[], const char *source, int unsafe)
 {
   int c;
 
+  optind = 1;
   while ((c = getopt_long(argc, argv, optstrig, long_options, NULL)) != -1) {
     switch(c) {
     case 'h':
@@ -491,6 +487,14 @@
       exit(0);
       break;
 
+    case 132: /* --dvipdfm */
+      dpx_conf.compat_mode = dpx_mode_compat_mode;
+      break;
+
+    case 133: /* --kpathsea-debug */
+      kpathsea_debug = atoi(optarg);
+      break;
+
     case 1000: /* --mvorigin */
       translate_origin = 1;
       break;
@@ -516,6 +520,14 @@
       dpx_conf.verbose_level++;
     }
   }
+
+  if (argc > optind + 1) {
+    fprintf(stderr, "%s: Multiple dvi filenames?", my_name);
+    usage();
+  } else if (argc > optind) { /* last argument */
+    dvi_filename = NEW(strlen(argv[optind]) + 5, char);  /* space to append ".dvi" */
+    strcpy(dvi_filename, argv[optind]);
+  }
 }
 
 /* Set "unsafe" to non-zero value when parsing config specials to
@@ -522,26 +534,18 @@
  * disallow overriding "D" option value.
  */
 static void
-do_args (int argc, char *argv[], const char *source, int unsafe)
+do_args_second_pass (int argc, char *argv[], const char *source, int unsafe)
 {
-  int c;
-  char *nextptr;
+  int         c;
+  char       *nextptr;
   const char *nnextptr;
 
   optind = 1;
   while ((c = getopt_long(argc, argv, optstrig, long_options, NULL)) != -1) {
     switch(c) {
-    case 'h': case 130: case 131: case 1000: case 'q': case 'v': /* already done */
+    case 'h': case 130: case 131: case 132: case 133: case 1000: case 'q': case 'v': /* already done */
       break;
 
-    case 132: /* --dvipdfm */
-      dpx_conf.compat_mode = dpx_mode_compat_mode;
-      break;
-
-    case 133: /* --kpathsea-debug */
-      kpathsea_debug = atoi(optarg);
-      break;
-
     case 'D':
       if (unsafe) {
         WARN("Ignoring \"D\" option for dvipdfmx:config special. (unsafe)");
@@ -683,7 +687,7 @@
     }
 
     case 'E':
-      always_embed = 1;
+      dpx_conf.ignore_font_license = 1;
       break;
 
     case 'e':
@@ -706,13 +710,7 @@
     return;
   }
 
-  if (argc > optind + 1) {
-    fprintf(stderr, "%s: Multiple dvi filenames?", my_name);
-    usage();
-  } else if (argc > optind) {
-    dvi_filename = NEW(strlen(argv[optind]) + 5, char);  /* space to append ".dvi" */
-    strcpy(dvi_filename, argv[optind]);
-  }
+  return;
 }
 
 static void
@@ -724,6 +722,8 @@
     RELEASE(pdf_filename);
   if (page_ranges)
     RELEASE(page_ranges);
+  if (filter_template)
+    RELEASE(filter_template);
 }
 
 static void
@@ -766,7 +766,7 @@
           argv[2] = parse_ident (&start, end);
       }
     }
-    do_args (argc, argv, config, 0);
+    do_args_second_pass (argc, argv, config, 0);
     while (argc > 1) {
       RELEASE (argv[--argc]);
     }
@@ -806,7 +806,7 @@
       argv[2] = parse_ident (start, end);
     }
   }
-  do_args (argc, argv, argv0, 1); /* Set to unsafe */
+  do_args_second_pass (argc, argv, argv0, 1); /* Set to unsafe */
   while (argc > 1) {
     RELEASE (argv[--argc]);
   }
@@ -890,9 +890,9 @@
         page_width = paper_width; page_height = paper_height;
         w = page_width; h = page_height; lm = landscape_mode;
         xo = x_offset; yo = y_offset;
-        dvi_scan_specials(page_no, has_paper_option, has_encrypt_option,
+        dvi_scan_specials(page_no,
                           &w, &h, &xo, &yo, &lm, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
-        if (lm != landscape_mode) {
+        if (lm != landscape_mode) { /* already swapped for the first page */
           SWAP(w, h);
           landscape_mode = lm;
         }
@@ -1013,7 +1013,7 @@
   double             dvi2pts;
   char              *base;
   struct pdf_setting settings;
-  char               uplain[MAX_PWD_LEN], oplain[MAX_PWD_LEN]; /* encryption password */
+  char               uplain[MAX_PWD_LEN+1], oplain[MAX_PWD_LEN+1]; /* encryption password */
   const char        *ids[4] = {NULL, NULL, NULL, NULL};
 
 #ifdef WIN32
@@ -1065,9 +1065,11 @@
   opterr = 0;
 
   /* Special-case single option --mvorigin, --help, --showpaper, or --version,
-     to avoid possible diagnostics about config files, etc.
-     Also handle -q and -v that cannot be set in config file. */
-  do_early_args(argc, argv);
+   * to avoid possible diagnostics about config files, etc.
+   * Also handle -q and -v that cannot be set in config file.
+   * Get input DVI file name too.
+   */
+  do_args_first_pass(argc, argv, NULL, 0);
 
   paperinit();
   system_default();
@@ -1076,8 +1078,6 @@
 
   read_config_file(DPX_CONFIG_FILE);
 
-  do_args (argc, argv, NULL, 0);
-
 #ifndef MIKTEX
   kpse_init_prog("", font_dpi, NULL, NULL);
   kpse_set_program_enabled(kpse_pk_format, true, kpse_src_texmf_cnf);
@@ -1111,23 +1111,27 @@
     dvi2pts = dvi_init(dvi_filename, mag);
     if (dvi2pts == 0.0)
       ERROR("dvi_init() failed!");
-
     ids[3] = dvi_comment(); /* Set PDF Creator entry */
-
-    if (do_encryption) {
-      get_enc_password(oplain, uplain);
-    }
-    dvi_scan_specials(0, has_paper_option, has_encrypt_option,
+    dvi_scan_specials(0,
                       &paper_width, &paper_height,
                       &x_offset, &y_offset, &landscape_mode,
                       &pdf_version_major, &pdf_version_minor,
                       &do_encryption, &key_bits, &permission, oplain, uplain);
-
     if (landscape_mode) {
       SWAP(paper_width, paper_height);
     }
   }
 
+  /* Command-line options take precedence */
+  {
+    int has_encrypt_special = do_encryption;
+
+    do_args_second_pass(argc, argv, NULL, 0);
+    if (do_encryption && !has_encrypt_special) {
+      get_enc_password(oplain, uplain);
+    }
+  }
+
   /* Encryption and Other Settings */
   {
 #define PRODUCER \

Modified: trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c	2018-09-16 13:28:49 UTC (rev 48677)
@@ -173,16 +173,16 @@
 
     ARC4(&arc4, 32, padded, tmp1);
     if (p->R >= 3) {
-    for (i = 1; i <= 19; i++) {
+      for (i = 1; i <= 19; i++) {
         memcpy(tmp2, tmp1, 32);
         for (j = 0; j < p->key_size; j++)
           key[j] = hash[j] ^ i;
         ARC4_set_key(&arc4, p->key_size, key);
         ARC4(&arc4, 32, tmp2, tmp1);
+      }
     }
-    }
+    memcpy(p->O, tmp1, 32);
   }
-  memcpy(p->O, hash, 32);
 }
 
 static void

Modified: trunk/Build/source/texk/dvipdfm-x/tt_aux.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/tt_aux.c	2018-09-16 05:36:36 UTC (rev 48676)
+++ trunk/Build/source/texk/dvipdfm-x/tt_aux.c	2018-09-16 13:28:49 UTC (rev 48677)
@@ -179,7 +179,7 @@
         WARN("Font \"%s\" permits \"Preview & Print\" embedding only **\n", fontname);
       *embed = 1;
     } else {
-      if (always_embed) {
+      if (dpx_conf.ignore_font_license) {
         if (dpx_conf.verbose_level > 0)
           WARN("Font \"%s\" may be subject to embedding restrictions **\n", fontname);
         *embed = 1;



More information about the tex-live-commits mailing list