fix infinite loop

This commit is contained in:
Pete Matsyburka
2026-08-10 11:48:05 +03:00
parent 8e254b7d3c
commit dd358a8401
2 changed files with 37 additions and 2 deletions
+4 -2
View File
@@ -264,7 +264,7 @@ module Templates
[process_fields_array(pdf, fields_index.values), annots_index]
end
def process_fields_array(pdf, array, acc = [])
def process_fields_array(pdf, array, acc = [], seen = Set.new.compare_by_identity)
array.each_with_index do |field, index|
next if field.nil?
@@ -272,10 +272,12 @@ module Templates
array[index] = field = HexaPDF::Type::AcroForm::Field.wrap(pdf, field)
end
next unless seen.add?(field.value)
if field.terminal_field?
acc << field
else
process_fields_array(pdf, field[:Kids], acc)
process_fields_array(pdf, field[:Kids], acc, seen)
end
end