Skip to content

Commit 8267cd3

Browse files
author
daniel.zhuang
committed
pdfiumload: guard against NULL-bitmaps
1 parent 2e78894 commit 8267cd3

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ master
1010
- tiffsave: always apply resolution unit conversion [kleisauke]
1111
- cache: suppress invalidation errors in release builds [kleisauke]
1212
- dzsave: IIIF: use named region of 'full' when no crop takes place [lovell]
13+
- pdfload: fix potential crash with pdfium < 6633 [zhifengzhuang]
1314

1415
5/6/25 8.17.0
1516

libvips/foreign/pdfiumload.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -584,47 +584,56 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region,
584584

585585
top = r->top;
586586
while (top < VIPS_RECT_BOTTOM(r)) {
587-
VipsRect rect;
588587
FPDF_BITMAP bitmap;
589588

589+
/* Is the rect within this page? It might not be if the output is more
590+
* than one tile wide and this page is narrower.
591+
*/
592+
VipsRect rect;
590593
vips_rect_intersectrect(r, &pdf->pages[i], &rect);
594+
if (rect.width > 0 &&
595+
rect.height > 0) {
591596

592-
if (vips_foreign_load_pdf_get_page(pdf, pdf->page_no + i))
593-
return -1;
597+
if (vips_foreign_load_pdf_get_page(pdf, pdf->page_no + i))
598+
return -1;
594599

595-
vips__worker_lock(&vips_pdfium_mutex);
600+
vips__worker_lock(&vips_pdfium_mutex);
596601

597-
/* 4 means RGBA.
598-
*/
599-
bitmap = FPDFBitmap_CreateEx(rect.width, rect.height, 4,
600-
VIPS_REGION_ADDR(out_region, rect.left, rect.top),
601-
VIPS_REGION_LSKIP(out_region));
602+
/* 4 means RGBA.
603+
*/
604+
if (!(bitmap = FPDFBitmap_CreateEx(rect.width, rect.height, 4,
605+
VIPS_REGION_ADDR(out_region, rect.left, rect.top),
606+
VIPS_REGION_LSKIP(out_region)))) {
607+
g_mutex_unlock(&vips_pdfium_mutex);
608+
return -1;
609+
}
602610

603-
/* Only paint the background if there's no transparency.
604-
*/
605-
if (!FPDFPage_HasTransparency(pdf->page)) {
606-
FPDF_DWORD ink = *((guint32 *) pdf->ink);
611+
/* Only paint the background if there's no transparency.
612+
*/
613+
if (!FPDFPage_HasTransparency(pdf->page)) {
614+
FPDF_DWORD ink = *((guint32 *) pdf->ink);
607615

608-
FPDFBitmap_FillRect(bitmap,
609-
0, 0, rect.width, rect.height, ink);
610-
}
616+
FPDFBitmap_FillRect(bitmap,
617+
0, 0, rect.width, rect.height, ink);
618+
}
611619

612-
// pdfium writes bgra by default, we need rgba
613-
FPDF_RenderPageBitmap(bitmap, pdf->page,
614-
pdf->pages[i].left - rect.left,
615-
pdf->pages[i].top - rect.top,
616-
pdf->pages[i].width, pdf->pages[i].height,
617-
0, FPDF_ANNOT | FPDF_REVERSE_BYTE_ORDER);
620+
// pdfium writes bgra by default, we need rgba
621+
FPDF_RenderPageBitmap(bitmap, pdf->page,
622+
pdf->pages[i].left - rect.left,
623+
pdf->pages[i].top - rect.top,
624+
pdf->pages[i].width, pdf->pages[i].height,
625+
0, FPDF_ANNOT | FPDF_REVERSE_BYTE_ORDER);
618626

619-
FPDF_FFLDraw(pdf->form, bitmap, pdf->page,
620-
pdf->pages[i].left - rect.left,
621-
pdf->pages[i].top - rect.top,
622-
pdf->pages[i].width, pdf->pages[i].height,
623-
0, FPDF_ANNOT | FPDF_REVERSE_BYTE_ORDER);
627+
FPDF_FFLDraw(pdf->form, bitmap, pdf->page,
628+
pdf->pages[i].left - rect.left,
629+
pdf->pages[i].top - rect.top,
630+
pdf->pages[i].width, pdf->pages[i].height,
631+
0, FPDF_ANNOT | FPDF_REVERSE_BYTE_ORDER);
624632

625-
FPDFBitmap_Destroy(bitmap);
633+
FPDFBitmap_Destroy(bitmap);
626634

627-
g_mutex_unlock(&vips_pdfium_mutex);
635+
g_mutex_unlock(&vips_pdfium_mutex);
636+
}
628637

629638
top += rect.height;
630639
i += 1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy