{"record":{"id":"a525a67a88d07179","repo":"docusealco/docuseal","slug":"failed-to-get-image-bitmap","errorCode":null,"errorMessage":"Failed to get image bitmap","messagePattern":"Failed to get image bitmap","errorType":"exception","errorClass":"Pdfium::PdfiumError","httpStatus":null,"severity":"error","filePath":"lib/pdfium.rb","lineNumber":1454,"sourceCode":"        matrix = matrix_ptr.read_array_of_float(6)\n\n        next if ((matrix[0] * matrix[3]) - (matrix[1] * matrix[2])).abs < 1e-9\n\n        bitmap = extract_image_bitmap(object_ptr)\n        pixel_rects = image_pixel_rects(matrix, bitmap[:width], bitmap[:height], overlapping)\n\n        next if pixel_rects.empty?\n\n        jpeg = yield(bitmap, pixel_rects)\n\n        load_image_jpeg(object_ptr, jpeg) if jpeg\n      end\n    end\n\n    def extract_image_bitmap(object_ptr)\n      bitmap_ptr = Pdfium.FPDFImageObj_GetBitmap(object_ptr)\n\n      raise PdfiumError, 'Failed to get image bitmap' if bitmap_ptr.nil? || bitmap_ptr.null?\n\n      format, bands = BITMAP_FORMAT_BANDS[Pdfium.FPDFBitmap_GetFormat(bitmap_ptr)]\n\n      raise PdfiumError, 'Unsupported image bitmap format' if format.nil?\n\n      image_width = Pdfium.FPDFBitmap_GetWidth(bitmap_ptr)\n      image_height = Pdfium.FPDFBitmap_GetHeight(bitmap_ptr)\n      stride = Pdfium.FPDFBitmap_GetStride(bitmap_ptr)\n\n      data = Pdfium.FPDFBitmap_GetBuffer(bitmap_ptr).read_bytes(stride * image_height)\n\n      row_size = image_width * bands\n\n      data = Array.new(image_height) { |row| data.byteslice(row * stride, row_size) }.join if stride != row_size\n\n      { data:, width: image_width, height: image_height, bands:, format: }\n    ensure\n      Pdfium.FPDFBitmap_Destroy(bitmap_ptr) if bitmap_ptr && !bitmap_ptr.null?","sourceCodeStart":1436,"sourceCodeEnd":1472,"githubUrl":"https://github.com/docusealco/docuseal/blob/004a22c1c88109c7ba0b567df011a8cb13894001/lib/pdfium.rb#L1436-L1472","documentation":"Raised by extract_image_bitmap when FPDFImageObj_GetBitmap returns NULL for an image object during image redaction. pdfium could not decode the image, which is common for JBIG2 or JPX (JPEG2000) encoded scans, corrupt image streams, or image masks that cannot be rasterized into a standard bitmap. There is no check_last_error; this is a hard stop for pixel-level redaction of that image.","triggerScenarios":"redact with an image_processor block on pages containing JBIG2-encoded scanned documents (fax/TIFF pipelines) or JPEG2000 images; truncated image streams inside damaged PDFs.","commonSituations":"Redacting scanned legal or medical documents; PDFs from high-compression archival systems.","solutions":["Rescue per image and fall back to covering the region with an opaque drawn rect","Rasterize or normalize the PDF first (ghostscript), then redact","Update libpdfium; decoder coverage improves across releases","Log non-decodable images for manual review in batch pipelines"],"exampleFix":"# before\npage.redact(rects) { |bitmap, pr| pixel_blacken(bitmap, pr) }\n\n# after\nbegin\n  page.redact(rects) { |bitmap, pr| pixel_blacken(bitmap, pr) }\nrescue Pdfium::PdfiumError => e\n  raise unless e.message == 'Failed to get image bitmap'\n  page.redact(rects) # rect-cover fallback still hides the content visually\nend","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  page.redact(rects) { |bitmap, pr| pixel_blacken(bitmap, pr) }\nrescue Pdfium::PdfiumError => e\n  raise unless e.message == 'Failed to get image bitmap'\n  page.redact(rects) # draw-only fallback for this page\nend","preventionTips":["Assume some inputs contain JBIG2/JPEG2000 images pdfium cannot decode; design the fallback first","Normalize scanned PDFs through ghostscript before pixel redaction","Log undecodable images so compliance-sensitive redaction can be reviewed manually"],"tags":["pdfium","redaction","images","decode","ruby"],"backgroundTag":"image-decode-failed","analyzedSha":"004a22c1c88109c7ba0b567df011a8cb13894001","analyzedAt":"2026-08-21T13:38:23.343Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}