Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d59e8b9

Browse files
committed
Merge branch '8.14'
2 parents da53d0e + 422c3b8 commit d59e8b9

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
TBD 8.14.4
2727

2828
- fix null-pointer dereference during svgload [kleisauke]
29+
- heif{load,save}: guard against NULL strings [kleisauke]
30+
- pdfiumload: fix rendering of pages with different sizes [DarthSim]
2931

3032
20/7/23 8.14.3
3133

libvips/foreign/heifload.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ void
215215
vips__heif_error(struct heif_error *error)
216216
{
217217
if (error->code)
218-
vips_error("heif", "%s (%d.%d)", error->message, error->code,
219-
error->subcode);
218+
vips_error("heif", "%s (%d.%d)",
219+
error->message ? error->message : "(null)",
220+
error->code, error->subcode);
220221
}
221222

222223
typedef struct _VipsForeignLoadHeifClass {

libvips/foreign/heifsave.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,11 @@ vips_foreign_save_heif_write(struct heif_context *ctx,
427427

428428
struct heif_error error;
429429

430-
error.code = 0;
431-
if (vips_target_write(heif->target, data, length))
432-
error.code = -1;
430+
error.code = heif_error_Ok;
431+
if (vips_target_write(heif->target, data, length)) {
432+
error.code = heif_error_Encoding_error;
433+
error.subcode = heif_suberror_Cannot_write_output_data;
434+
}
433435

434436
return error;
435437
}

libvips/foreign/pdfiumload.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ EOF
111111
#include <fpdf_edit.h>
112112
#include <fpdf_formfill.h>
113113

114+
#define TILE_SIZE (4000)
115+
114116
typedef struct _VipsForeignLoadPdf {
115117
VipsForeignLoad parent_object;
116118

@@ -331,8 +333,7 @@ vips_foreign_load_pdf_build(VipsObject *object)
331333
static VipsForeignFlags
332334
vips_foreign_load_pdf_get_flags_filename(const char *filename)
333335
{
334-
/* We can't render any part of the page on demand, but we can render
335-
* separate pages. Might as well call ourselves partial.
336+
/* We can render any part of the page on demand.
336337
*/
337338
return VIPS_FOREIGN_PARTIAL;
338339
}
@@ -401,9 +402,9 @@ vips_foreign_load_pdf_set_image(VipsForeignLoadPdf *pdf, VipsImage *out)
401402
printf("vips_foreign_load_pdf_set_image: %p\n", pdf);
402403
#endif /*DEBUG*/
403404

404-
/* We render to a linecache, so fat strips work well.
405+
/* We render to a tilecache, so it has to be SMALLTILE.
405406
*/
406-
if (vips_image_pipelinev(out, VIPS_DEMAND_STYLE_FATSTRIP, NULL))
407+
if (vips_image_pipelinev(out, VIPS_DEMAND_STYLE_SMALLTILE, NULL))
407408
return -1;
408409

409410
/* Extract and attach metadata. Set the old name too for compat.
@@ -579,6 +580,11 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region,
579580
if (VIPS_RECT_BOTTOM(&pdf->pages[i]) > r->top)
580581
break;
581582

583+
/* Reset out region. Otherwise there might be parts of previous pages
584+
* left.
585+
*/
586+
vips_region_black(or);
587+
582588
top = r->top;
583589
while (top < VIPS_RECT_BOTTOM(r)) {
584590
VipsRect rect;
@@ -607,7 +613,9 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region,
607613
}
608614

609615
FPDF_RenderPageBitmap(bitmap, pdf->page,
610-
0, 0, rect.width, rect.height,
616+
pdf->pages[i].left - rect.left,
617+
pdf->pages[i].top - rect.top,
618+
pdf->pages[i].width, pdf->pages[i].height,
611619
0, 0);
612620

613621
FPDF_FFLDraw(pdf->form, bitmap, pdf->page,
@@ -653,20 +661,15 @@ vips_foreign_load_pdf_load(VipsForeignLoad *load)
653661
G_CALLBACK(vips_foreign_load_pdf_minimise), pdf);
654662

655663
vips_foreign_load_pdf_set_image(pdf, t[0]);
656-
if (vips_image_generate(t[0],
657-
NULL, vips_foreign_load_pdf_generate, NULL, pdf, NULL))
658-
return -1;
659664

660-
/* PDFium does not like rendering parts of pages :-( always render
661-
* complete pages.
662-
*/
663-
if (vips_tilecache(t[0], &t[1],
664-
"tile_width", pdf->pages[0].width,
665-
"tile_height", pdf->pages[0].height,
666-
"max_tiles", 1,
667-
NULL))
668-
return -1;
669-
if (vips_image_write(t[1], load->real))
665+
if (vips_image_generate(t[0],
666+
NULL, vips_foreign_load_pdf_generate, NULL, pdf, NULL) ||
667+
vips_tilecache(t[0], &t[1],
668+
"tile_width", TILE_SIZE,
669+
"tile_height", TILE_SIZE,
670+
"max_tiles", 2 * (1 + t[0]->Xsize / TILE_SIZE),
671+
NULL) ||
672+
vips_image_write(t[1], load->real))
670673
return -1;
671674

672675
return 0;
@@ -676,7 +679,7 @@ static void *
676679
vips_foreign_load_pdf_once_init(void *client)
677680
{
678681
/* We must make the mutex on class init (not _build) since we
679-
* can lock ebven if build is not called.
682+
* can lock even if build is not called.
680683
*/
681684
vips_pdfium_mutex = vips_g_mutex_new();
682685

0 commit comments

Comments
 (0)