mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 14:42:32 -05:00
fix pdf validation
This commit is contained in:
1 parent
887d80f6d7
commit
ec04a95e36
2 files changed
+11
-4
No files matched your search
+2
-2
@@ -2306,14 +2306,14 @@ class Pdfium
|
||||
[PageObject, *to_a].hash
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def object_ptr
|
||||
page.ensure_not_closed!
|
||||
|
||||
Pdfium.FPDFPage_GetObject(page.page_ptr, index)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def read_bounds
|
||||
buffer = Array.new(4) { FFI::MemoryPointer.new(:float) }
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ module VerifyPdfSignature
|
||||
io.seek(0)
|
||||
|
||||
Pdfium::Document.open_bytes(io.read(signed_end)) do |signed_document|
|
||||
next false unless signed_document.valid_cross_reference_table?
|
||||
next true unless signed_document.valid_cross_reference_table?
|
||||
|
||||
serialized_document(signed_document) != serialized_document(document)
|
||||
end
|
||||
@@ -182,13 +182,20 @@ module VerifyPdfSignature
|
||||
def serialized_document(document)
|
||||
pages = (0...document.page_count).map do |index|
|
||||
page = document.get_page(index)
|
||||
objects = page.objects.map { |object| [*object.to_a, image_digest(page, object)] }
|
||||
|
||||
[page.rotation, page.objects, page.annotations, page.text]
|
||||
[page.rotation, objects, page.annotations, page.text]
|
||||
end
|
||||
|
||||
[pages, document.bookmarks]
|
||||
end
|
||||
|
||||
def image_digest(page, object)
|
||||
return unless object.image?
|
||||
|
||||
Digest::SHA256.hexdigest(page.extract_image_bitmap(object.object_ptr)[:data])
|
||||
end
|
||||
|
||||
def signed_data(io, byte_range)
|
||||
byte_range.each_slice(2).map do |offset, length|
|
||||
io.seek(offset)
|
||||
|
||||
Reference in new issue
Block a user