From bafd207323eedd057f88a3cb2936a9ca06da406a Mon Sep 17 00:00:00 2001 From: Andre Renaud Date: Mon, 2 Mar 2026 10:11:09 +1300 Subject: [PATCH 1/4] Missing Symbol & Zapfdingbats font Fix possible issue with bad user input --- pdfgen.c | 27 +++++++++++++++++---------- pdfgen.h | 10 +++++----- tests/massive-file.c | 32 ++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/pdfgen.c b/pdfgen.c index 2448dae..9439e30 100644 --- a/pdfgen.c +++ b/pdfgen.c @@ -210,12 +210,21 @@ static const char png_chunk_end[] = "IEND"; // PDF standard fonts static const char *valid_fonts[] = { - "Times-Roman", "Times-Bold", - "Times-Italic", "Times-BoldItalic", - "Helvetica", "Helvetica-Bold", - "Helvetica-Oblique", "Helvetica-BoldOblique", - "Courier", "Courier-Bold", - "Courier-Oblique", "Courier-BoldOblique"}; + "Times-Roman", + "Times-Bold", + "Times-Italic", + "Times-BoldItalic", + "Helvetica", + "Helvetica-Bold", + "Helvetica-Oblique", + "Helvetica-BoldOblique", + "Courier", + "Courier-Bold", + "Courier-Oblique", + "Courier-BoldOblique", + "Symbol", + "ZapfDingbats", +}; typedef struct pdf_object pdf_object; @@ -446,10 +455,8 @@ static inline void *flexarray_get(const struct flexarray *flex, int index) */ #define INIT_DSTR \ - (struct dstr) \ - { \ - .static_data = {0}, .data = NULL, .alloc_len = 0, .used_len = 0 \ - } + (struct dstr){ \ + .static_data = {0}, .data = NULL, .alloc_len = 0, .used_len = 0} static char *dstr_data(struct dstr *str) { diff --git a/pdfgen.h b/pdfgen.h index 69e41f8..94e83fb 100644 --- a/pdfgen.h +++ b/pdfgen.h @@ -205,13 +205,13 @@ struct pdf_path_operation { * Convert a value in inches into a number of points. * @param inch inches value to convert to points */ -#define PDF_INCH_TO_POINT(inch) ((float)((inch)*72.0f)) +#define PDF_INCH_TO_POINT(inch) ((float)((inch) * 72.0f)) /** * Convert a value in milli-meters into a number of points. * @param mm millimeter value to convert to points */ -#define PDF_MM_TO_POINT(mm) ((float)((mm)*72.0f / 25.4f)) +#define PDF_MM_TO_POINT(mm) ((float)((mm) * 72.0f / 25.4f)) /*! Point width of a standard US-Letter page */ #define PDF_LETTER_WIDTH PDF_INCH_TO_POINT(8.5f) @@ -237,7 +237,7 @@ struct pdf_path_operation { * in PDFGen */ #define PDF_RGB(r, g, b) \ - (uint32_t)((((r)&0xff) << 16) | (((g)&0xff) << 8) | (((b)&0xff))) + (uint32_t)((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | (((b) & 0xff))) /** * Convert four 8-bit ARGB values into a single packed 32-bit @@ -246,8 +246,8 @@ struct pdf_path_operation { * (transparent) */ #define PDF_ARGB(a, r, g, b) \ - (uint32_t)(((uint32_t)((a)&0xff) << 24) | (((r)&0xff) << 16) | \ - (((g)&0xff) << 8) | (((b)&0xff))) + (uint32_t)(((uint32_t)((a) & 0xff) << 24) | (((r) & 0xff) << 16) | \ + (((g) & 0xff) << 8) | (((b) & 0xff))) /*! Utility macro to provide bright red */ #define PDF_RED PDF_RGB(0xff, 0, 0) diff --git a/tests/massive-file.c b/tests/massive-file.c index a5a1606..6d715a7 100644 --- a/tests/massive-file.c +++ b/tests/massive-file.c @@ -1,4 +1,5 @@ #include "pdfgen.h" +#include #include int main(int argc, char **argv) @@ -9,19 +10,22 @@ int main(int argc, char **argv) if (argc > 1) { pagecount = atoi(argv[1]); - } - pdf_set_font(pdf, "Times-Roman"); - for (int i = 0; i < pagecount; i++) { - char str[64]; - pdf_append_page(pdf); - sprintf(str, "page %d", i); - pdf_add_text(pdf, NULL, str, 12, 50, 20, PDF_BLACK); + if (pagecount < 1 || pagecount > INT_MAX) { + pagecount = 10; + } + pdf_set_font(pdf, "Times-Roman"); + for (int i = 0; i < pagecount; i++) { + char str[64]; + pdf_append_page(pdf); + sprintf(str, "page %d", i); + pdf_add_text(pdf, NULL, str, 12, 50, 20, PDF_BLACK); - pdf_add_image_file(pdf, NULL, 100, 500, 50, 150, "data/penguin.jpg"); - } + pdf_add_image_file(pdf, NULL, 100, 500, 50, 150, + "data/penguin.jpg"); + } - sprintf(filename, "massive-%d.pdf", pagecount); - pdf_save(pdf, filename); - pdf_destroy(pdf); - return 0; -} \ No newline at end of file + sprintf(filename, "massive-%d.pdf", pagecount); + pdf_save(pdf, filename); + pdf_destroy(pdf); + return 0; + } \ No newline at end of file From 43cee3c3381f1ac757c69f140974d01ee1898876 Mon Sep 17 00:00:00 2001 From: Andre Renaud Date: Mon, 2 Mar 2026 10:12:22 +1300 Subject: [PATCH 2/4] typo --- tests/massive-file.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/massive-file.c b/tests/massive-file.c index 6d715a7..aae3011 100644 --- a/tests/massive-file.c +++ b/tests/massive-file.c @@ -11,21 +11,22 @@ int main(int argc, char **argv) if (argc > 1) { pagecount = atoi(argv[1]); if (pagecount < 1 || pagecount > INT_MAX) { - pagecount = 10; + fprintf(stderr, "Invalid page count: %d\n", pagecount); + return 1; } - pdf_set_font(pdf, "Times-Roman"); - for (int i = 0; i < pagecount; i++) { - char str[64]; - pdf_append_page(pdf); - sprintf(str, "page %d", i); - pdf_add_text(pdf, NULL, str, 12, 50, 20, PDF_BLACK); + } + pdf_set_font(pdf, "Times-Roman"); + for (int i = 0; i < pagecount; i++) { + char str[64]; + pdf_append_page(pdf); + sprintf(str, "page %d", i); + pdf_add_text(pdf, NULL, str, 12, 50, 20, PDF_BLACK); - pdf_add_image_file(pdf, NULL, 100, 500, 50, 150, - "data/penguin.jpg"); - } + pdf_add_image_file(pdf, NULL, 100, 500, 50, 150, "data/penguin.jpg"); + } - sprintf(filename, "massive-%d.pdf", pagecount); - pdf_save(pdf, filename); - pdf_destroy(pdf); - return 0; - } \ No newline at end of file + sprintf(filename, "massive-%d.pdf", pagecount); + pdf_save(pdf, filename); + pdf_destroy(pdf); + return 0; +} \ No newline at end of file From 39c29538eed1c154143b0e98209395188f4d368e Mon Sep 17 00:00:00 2001 From: Andre Renaud Date: Mon, 2 Mar 2026 10:16:55 +1300 Subject: [PATCH 3/4] Reinstate whitespace --- pdfgen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pdfgen.c b/pdfgen.c index 9439e30..f916161 100644 --- a/pdfgen.c +++ b/pdfgen.c @@ -455,8 +455,10 @@ static inline void *flexarray_get(const struct flexarray *flex, int index) */ #define INIT_DSTR \ - (struct dstr){ \ - .static_data = {0}, .data = NULL, .alloc_len = 0, .used_len = 0} + (struct dstr) \ + { \ + .static_data = {0}, .data = NULL, .alloc_len = 0, .used_len = 0 \ + } static char *dstr_data(struct dstr *str) { From 1a49855309e1428d2d155419bcad00757e81939c Mon Sep 17 00:00:00 2001 From: Andre Renaud Date: Mon, 2 Mar 2026 10:21:05 +1300 Subject: [PATCH 4/4] Undo formatting clang-format-10 & latest differ --- pdfgen.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pdfgen.h b/pdfgen.h index 94e83fb..69e41f8 100644 --- a/pdfgen.h +++ b/pdfgen.h @@ -205,13 +205,13 @@ struct pdf_path_operation { * Convert a value in inches into a number of points. * @param inch inches value to convert to points */ -#define PDF_INCH_TO_POINT(inch) ((float)((inch) * 72.0f)) +#define PDF_INCH_TO_POINT(inch) ((float)((inch)*72.0f)) /** * Convert a value in milli-meters into a number of points. * @param mm millimeter value to convert to points */ -#define PDF_MM_TO_POINT(mm) ((float)((mm) * 72.0f / 25.4f)) +#define PDF_MM_TO_POINT(mm) ((float)((mm)*72.0f / 25.4f)) /*! Point width of a standard US-Letter page */ #define PDF_LETTER_WIDTH PDF_INCH_TO_POINT(8.5f) @@ -237,7 +237,7 @@ struct pdf_path_operation { * in PDFGen */ #define PDF_RGB(r, g, b) \ - (uint32_t)((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | (((b) & 0xff))) + (uint32_t)((((r)&0xff) << 16) | (((g)&0xff) << 8) | (((b)&0xff))) /** * Convert four 8-bit ARGB values into a single packed 32-bit @@ -246,8 +246,8 @@ struct pdf_path_operation { * (transparent) */ #define PDF_ARGB(a, r, g, b) \ - (uint32_t)(((uint32_t)((a) & 0xff) << 24) | (((r) & 0xff) << 16) | \ - (((g) & 0xff) << 8) | (((b) & 0xff))) + (uint32_t)(((uint32_t)((a)&0xff) << 24) | (((r)&0xff) << 16) | \ + (((g)&0xff) << 8) | (((b)&0xff))) /*! Utility macro to provide bright red */ #define PDF_RED PDF_RGB(0xff, 0, 0)