Just committed the following three fixes (patches attached) * libgnomeprint/gnome-print-pdf-t1.c (gnome_print_pdf_t1_determine_lengths_pfa): Just look for the last occurrence of 'cleartomark' in the file instead of making guesses as to what is after. The Adobe spec allows comments/PS code after the cleartomark and, e.g., fonts generated by pfaedit have such. This change was to fix problems with embedding PS files that ended, in for instance, cleartomark {revert}if As pfaedit generates them. Looking at the Adobe docs, basically anything is allowed after cleartomark so I changed the code to just search for the last cleartomark. * libgnomeprint/gnome-print-pdf.c (gnome_print_pdf_set_font_real): Initialize encodedname to NULL so we don't free a random bit of memory. This was causing a random memory pointer to be freed with subsequent badness. * libgnomeprint/gnome-print.c (gnome_print_buffer_mmap): Fix problems with not setting b->buf_size that were causing the PS2 backend not to be able to embed fonts. Various code depended on b->buf_size being set, but it almost never was. This patch makes sure that it always is. It also fixes the (should not happen) case where we get an early EOF. Regards, Owen
Index: libgnomeprint/gnome-print-pdf-t1.c =================================================================== RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/gnome-print-pdf-t1.c,v retrieving revision 1.8 diff -u -p -r1.8 gnome-print-pdf-t1.c --- libgnomeprint/gnome-print-pdf-t1.c 28 Jan 2003 02:20:35 -0000 1.8 +++ libgnomeprint/gnome-print-pdf-t1.c 15 Jul 2004 20:10:05 -0000 @@ -48,6 +48,37 @@ struct _GnomePrintPdfT1Font { GnomePrintBuffer b; }; +/* g_strstr_len contains checks for embedded NULs that + * might confuse us and are slow, so here's a simplified + * version. + */ +static char * +my_strrstr_len (const gchar *haystack, + gssize haystack_len, + const gchar *needle) +{ + gsize needle_len = strlen (needle); + const gchar *p; + gsize i; + + if (haystack_len < needle_len) + return NULL; + + p = haystack + haystack_len - needle_len; + while (p >= haystack) { + for (i = 0; i < needle_len; i++) + if (p[i] != needle[i]) + goto next; + + return (gchar *)p; + + next: + p--; + } + + return NULL; +} + static gint gnome_print_pdf_t1_determine_lengths_pfa (GnomePrintPdfT1Font *font) { @@ -71,34 +102,16 @@ gnome_print_pdf_t1_determine_lengths_pfa goto determine_lengths_pfa_error; font->length[0] = len; - /* Get the length of segment 2, scaning from the end of the + /* Get the length of segment 2, scanning from the end of the * font. First look for the cleartomark, then rewind 512 * zeros, which will most likely have newlines between them (Chema) */ - - /* Rewind newlines at the end of the font, no more than 10 */ - pos = font->b.buf + font->b.buf_size; - error = 2; - if (*pos != '\0' ) - goto determine_lengths_pfa_error; - pos--; - i = 0; - while ((*pos == '\n' || *pos == '\r') && (i < 10)) { - pos--; i++; - - } - /* the first non-newline char should be a k for "cleartomarK" */ - error = 3; - if (*pos != 'k') - goto determine_lengths_pfa_error; - - /* Check that "cleartomark" is there */ - i = strlen (T1_SEGMENT_3_END); - pos = pos - i + 1; - error = 4; - if (strncmp (pos, T1_SEGMENT_3_END, i)) + error = 2; + pos = my_strrstr_len (pos, font->b.buf_size - len, T1_SEGMENT_3_END); + if (!pos) goto determine_lengths_pfa_error; + pos --; /* Rewind 512 zeros */
Index: libgnomeprint/gnome-print-pdf.c =================================================================== RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/gnome-print-pdf.c,v retrieving revision 1.30 diff -u -p -r1.30 gnome-print-pdf.c --- libgnomeprint/gnome-print-pdf.c 2 Jul 2004 13:28:04 -0000 1.30 +++ libgnomeprint/gnome-print-pdf.c 15 Jul 2004 20:10:05 -0000 @@ -1684,7 +1684,7 @@ gnome_print_pdf_set_font_real (GnomePrin GnomePrintPdfFont *font = NULL; GnomeFontFace *face; GList *needle; - guchar *encodedname; + guchar *encodedname = NULL; gint i; face = gnome_font->face;
Index: libgnomeprint/gnome-print.c =================================================================== RCS file: /cvs/gnome/libgnomeprint/libgnomeprint/gnome-print.c,v retrieving revision 1.104 diff -u -p -r1.104 gnome-print.c --- libgnomeprint/gnome-print.c 9 Jul 2004 02:36:38 -0000 1.104 +++ libgnomeprint/gnome-print.c 15 Jul 2004 20:10:05 -0000 @@ -592,20 +592,23 @@ gnome_print_buffer_mmap (GnomePrintBuffe g_warning ("Can't mmap file %s - attempting a fallback...", file_name); b->buf = g_try_malloc (s.st_size); + b->buf_size = s.st_size; if (b->buf != NULL) { ssize_t nread, total_read; nread = total_read = 0; while (total_read < s.st_size) { - nread = read (fh, b->buf + total_read, GP_MMAP_BUFSIZ); + nread = read (fh, b->buf + total_read, + MIN (GP_MMAP_BUFSIZ, s.st_size - total_read)); if (nread == 0) { - b->buf_size = s.st_size; + b->buf_size = total_read; break; /* success */ } else if (nread == -1) { if (errno != EINTR) { g_free (b->buf); b->buf = NULL; + b->buf_size = 0; break; /* failure */ } } else @@ -614,6 +617,7 @@ gnome_print_buffer_mmap (GnomePrintBuffe } } else { b->was_mmaped = TRUE; + b->buf_size = s.st_size; } #ifdef HAVE_BROKEN_MMAP
Attachment:
signature.asc
Description: This is a digitally signed message part