Package: ppdfilt
Version: 2:0.10-7
Severity: normal

Acroread is producing postscript files with

%%BeginBinary: 1
img
%%EndBinary

(don't ask me why it is using BeginBinary instead of BeginData,
and why it is 1 when Adobe says unit is bytes unless Lines is given,
but that does not matter for this problem. All that matter is that
the number is quite low).

If ppdfilt -2 hits such a statement, is always copies 8192 bytes
verbatimly, thus sometimes overlooking a %%Page header, which
results in multiple pages printed on the same place.

It also does output the %%End but not the %%Begin.

The attached patch fixes both issues here.

Hochachtungsvoll,
        Bernhard R. Link
--- libppd-0.10.orig/src/ppdfilt.c
+++ libppd-0.10/src/ppdfilt.c
@@ -570,10 +590,15 @@
       else if (strncmp(line, "%%BeginBinary:", 14) == 0
               || (strncmp(line, "%%BeginData:", 12) == 0
                   && strstr(line, "Binary") != NULL)) {
+       // Output line to keep Begin/End intact
+       puts(line);
        // Copy binary data...
        tbytes = atoi(strchr(line, ':') + 1);
        while (tbytes > 0) {
-         nbytes = fread(line, 1, sizeof(line), fp);
+         if ((size_t)tbytes < sizeof(line))
+           nbytes = fread(line, 1, tbytes, fp);
+         else
+           nbytes = fread(line, 1, sizeof(line), fp);
          fwrite(line, 1, nbytes, stdout);
          tbytes -= nbytes;
        }
@@ -637,10 +662,22 @@
       } else if (strncmp(line, "%%BeginBinary:", 14) == 0
                 || (strncmp(line, "%%BeginData:", 12) == 0
                     && strstr(line, "Binary") != NULL)) {
+       // First copy line (so that the %%End is not alone:
+       if (!get_sloworder(flags))
+         puts(line);
+       if (get_slowcollate(flags) || get_sloworder(flags)) {
+         fputs(line, temp);
+         putc('\n', temp);
+       }
        // Copy binary data...
+       // TODO: this still need support for 
+       // '%%BeginData num Bynary Lines'
        tbytes = atoi(strchr(line, ':') + 1);
        while (tbytes > 0) {
-         nbytes = fread(line, 1, sizeof(line), fp);
+         if ((size_t)tbytes < sizeof(line))
+           nbytes = fread(line, 1, tbytes, fp);
+         else
+           nbytes = fread(line, 1, sizeof(line), fp);
 
          if (!get_sloworder(flags))
            fwrite(line, 1, nbytes, stdout);

Reply via email to