From 76f6b49731e3541b3e605dac96e659ed25b33e11 Mon Sep 17 00:00:00 2001 From: poire-z Date: Sat, 22 Apr 2017 15:40:10 +0200 Subject: [PATCH] Fix crash with kopt semi-auto crop on blank page When such blank page has only a few black pixels (dust), it would result in a really small cropped area, than when scaled to fit screen, would cause a crash with : ./ffi/mupdf.lua:63: could not allocate pixmap: malloc of array (451342 x 612558 bytes) failed (integer overflow) (1) Fix similar to what is done in KoptInterface:getAutoBBox(): when cropped area too small, fall back to whole page (or here: to user's manually set area). --- frontend/document/koptinterface.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index a8deaadcb..7ffbbda4c 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -180,6 +180,11 @@ function KoptInterface:getSemiAutoBBox(doc, pageno) auto_bbox.x1 = auto_bbox.x1 + bbox.x0 auto_bbox.y1 = auto_bbox.y1 + bbox.y0 logger.dbg("Semi-auto detected bbox", auto_bbox) + local native_size = Document.getNativePageDimensions(doc, pageno) + if (auto_bbox.x1 - auto_bbox.x0)/native_size.w < 0.1 and (auto_bbox.y1 - auto_bbox.y0)/native_size.h < 0.1 then + logger.dbg("Semi-auto detected bbox too small, using manual bbox") + auto_bbox = bbox + end page:close() Cache:insert(hash, CacheItem:new{ semiautobbox = auto_bbox }) kc:free()