-
-
Notifications
You must be signed in to change notification settings - Fork 707
pdfiumload: guard against NULL
-bitmaps
#4599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I wonder if commit 2fdab9b is also related here.
This effectively reverts commit 985fb1d, I'm not sure if that's wanted. |
Commit 2fdab9b seems not to related here. Older pdfium(<6633) will crash when an empty bitmap pass to FPDF_FFLDraw. We should check the rect width&height before we call FPDF_FFLDraw? |
Hi @zhifengzhuang, thank you for this PR!
I think that's unrelated -- this PR fixes the case where you have a narrow page and the tilecache asks for a rect outside the page boundary. poppler deals with this gracefully, but (as @zhifengzhuang says) older pdfiums will crash.
I agree, I'm not sure about the change to background. I think this is a case where PDFium has better transparency support than poppler, so we don't want to match the behaviour exactly. |
libvips/foreign/pdfiumload.c
Outdated
/* | ||
* Same with popperload | ||
*/ | ||
vips_region_paint_pel(out_region, r, pdf->ink); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should do this. We set the background when required with FPDFBitmap_FillRect()
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should do this. We set the background when required with
FPDFBitmap_FillRect()
below.
So maybe we could paint background color to out_region when rect is empty?
libvips/foreign/pdfiumload.c
Outdated
@@ -592,39 +597,43 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region, | |||
if (vips_foreign_load_pdf_get_page(pdf, pdf->page_no + i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could move inside the rect size test if()
, eg.:
top = r->top;
while (top < VIPS_RECT_BOTTOM(r)) {
FPDF_BITMAP bitmap;
/* Is the rect within this page? It might not be if the output is more
* than one tile wide and this page is narrower.
*/
VipsRect rect;
vips_rect_intersectrect(r, &pdf->pages[i], &rect);
if (rect.width > 0 &&
rect.height > 0) {
if (vips_foreign_load_pdf_get_page(pdf, pdf->page_no + i))
return -1;
vips__worker_lock(&vips_pdfium_mutex);
/* 4 means RGBA.
*/
bitmap = FPDFBitmap_CreateEx(rect.width, rect.height, 4,
VIPS_REGION_ADDR(out_region, rect.left, rect.top),
VIPS_REGION_LSKIP(out_region));
... etc
I can confirm that this issue reproduces with PDFium 6611 but does not occur with PDFium 6666. Tested using: Details# export PDFIUM_VERSION=6666
export PDFIUM_VERSION=6611
mkdir -p $HOME/pdfium-linux-x64/lib/pkgconfig
curl -Ls https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F$PDFIUM_VERSION/pdfium-linux-x64.tgz | tar xzC $HOME/pdfium-linux-x64
cat > $HOME/pdfium-linux-x64/lib/pkgconfig/pdfium.pc << EOF
prefix=$HOME/pdfium-linux-x64
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: pdfium
Description: PDFium
Version: $PDFIUM_VERSION
Libs: -L\${libdir} -lpdfium
Cflags: -I\${includedir}
EOF
export PKG_CONFIG_PATH=$HOME/pdfium-linux-x64/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
export LD_LIBRARY_PATH=$HOME/pdfium-linux-x64/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
pkg-config --exists --print-errors "pdfium >= 4200" && echo OK
meson setup build --prefix=/usr -Ddeprecated=false -Dexamples=false -Dintrospection=disabled
meson compile -Cbuild
sudo meson install -Cbuild It looks like this was fixed with commit https://pdfium.googlesource.com/pdfium/+/f8e68068d9301f24993afd94c270860dc0244674, i.e. this diff: @@ -696,8 +727,13 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
int size_y,
int rotate,
int flags) {
- FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y,
- rotate, flags);
+ CFX_DIBitmap* cbitmap = CFXDIBitmapFromFPDFBitmap(bitmap);
+ if (!cbitmap) {
+ return;
+ }
+
+ FFLCommon(hHandle, page, cbitmap, start_x, start_y, size_x, size_y, rotate,
+ flags);
}
#if defined(PDF_USE_SKIA) Which ensures |
7f8f74d
to
13eef6f
Compare
Thanks for replying. I remove vips_region_paint_pel and update test if(). |
Yes,it was fixed https://pdfium.googlesource.com/pdfium/+/f8e68068d9301f24993afd94c270860dc0244674 (Just between 6632 & 6633) |
b45bf87
to
6977e1e
Compare
NULL
-bitmaps
I've updated this PR to target the |
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
Great! Let's merge! Thank you for doing this work, @zhifengzhuang, this is a good thing to fix. This change will be in libvips 8.17.1. |
052201055248624de6f3063354544793.pdf
: vips pdfload 052201055248624de6f3063354544793.pdf out.jpeg --n=-1 --dpi=180