metanorma / vectory

Convert between vector image formats (Ruby)
2 stars 0 forks source link

Crash on image_resize #41

Closed opoudjis closed 5 months ago

opoudjis commented 6 months ago

Newly affecting BSI document:

undefined method `zero?' for nil:NilClass
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/vectory-0.7.5/lib/vectory/image_resize.rb:47:in `fill_size'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/vectory-0.7.5/lib/vectory/image_resize.rb:40:in `image_size_fillin'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/vectory-0.7.5/lib/vectory/image_resize.rb:13:in `call'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/html_function/postprocess.rb:88:in `block in resize_images'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.6-arm64-darwin/lib/nokogiri/xml/node_set.rb:235:in `block in each'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.6-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `upto'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/nokogiri-1.15.6-arm64-darwin/lib/nokogiri/xml/node_set.rb:234:in `each'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/html_function/postprocess.rb:85:in `resize_images'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/html_function/postprocess.rb:17:in `toHTML'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/html_function/postprocess.rb:11:in `postprocess'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/convert.rb:171:in `convert'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/isodoc-2.10.2/lib/isodoc/html_convert.rb:26:in `convert'
/Users/nickn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/metanorma-bsi-1.2.6/lib/metanorma/bsi/processor.rb:44:in `output'

To replicate:

git clone https://github.com/metanorma/mn-samples-bsi.git
bundle update
cd sources/bs-1234-2019
bundle exec metanorma compile document.adoc

I am zipping the folder and sending it to you on Skype.

The images are SVG, and all are provided without image sizes:

08-figures.adoc:image::fig-1.svg[]
08-figures.adoc:image::fig-2a.svg[]
08-figures.adoc:image::fig-2b.svg[]
08-figures.adoc:image:fig-2-key-1.svg[] {blank}:: Hole
08-figures.adoc:image:fig-2-key-2.svg[] {blank}:: Thin-edged knockout
08-figures.adoc:image::fig-3.svg[]
aa-example.adoc:image::fig-a1.svg[]
alexeymorozov commented 6 months ago

Fixed and released in v0.7.6 as seen in the workflow:

https://github.com/metanorma/metanorma-cli/actions/runs/8972014184/job/24691227674

opoudjis commented 6 months ago

New crash, in isodoc rspec test:

i = Nokogiri::XML("<img src=\"data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjw/eG1sLXN0eWxlc2hlZXQgdHlwZT0idGV4dC94c2wiIGhyZWY9Ii4uLy4uLy4uL3hzbC9yZXNfZG9jL2ltZ2ZpbGUueHNsIj8+CjwhRE9DVFlQRSBpbWdmaWxlLmNvbnRlbnQgU1lTVEVNICIuLi8uLi8uLi9kdGQvdGV4dC5lbnQiPgo8aW1nZmlsZS5jb250ZW50IG1vZHVsZT0iZnVuZGFtZW50YWxzX29mX3Byb2R1Y3RfZGVzY3JpcHRpb25fYW5kX3N1cHBvcnQiIGZpbGU9ImFjdGlvbl9zY2hlbWFleHBnMS54bWwiPgo8aW1nIHNyYz0iYWN0aW9uX3NjaGVtYWV4cGcxLmdpZiI+CjxpbWcuYXJlYSBzaGFwZT0icmVjdCIgY29vcmRzPSIyMTAsMTg2LDM0MywyMjciIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9iYXNpY19hdHRyaWJ1dGVfc2NoZW1hL2Jhc2ljX2F0dHJpYnV0ZV9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMTAsMTAsOTYsNTEiIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9hY3Rpb25fc2NoZW1hL2FjdGlvbl9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMjEwLDI2NCwzNTgsMzA1IiBocmVmPSIuLi8uLi9yZXNvdXJjZXMvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEueG1sIiAvPgo8L2ltZz4KPC9pbWdmaWxlLmNvbnRlbnQ+Cg==\" height=\"20\" width=\"auto\"/>").root
Vectory::ImageResize.new.call(i, loc, @maxheight, @maxwidth)

crashes on

    def get_image_size(img, path)
      detected = ImageSize.path(path).size
      realsize = detected unless detected.all? { |x| x.nil? || x.zero? }
      s = image_size_interpret(img, realsize || [nil, nil])
      image_size_zeroes_complete(s, realsize)
    end

Because ImageSize.path(path).size is returning nil.

Presumably it will be enough to change the line to unless detected.nil? || detected.all? { |x| x.nil? || x.zero? }

alexeymorozov commented 6 months ago

Eeerr, sorry! I'll fix it.

alexeymorozov commented 6 months ago

@opoudjis Did it fail at GHA somewhere? I'd like to ensure that other specs don't fail too.

opoudjis commented 6 months ago

I did see it in isodoc, but I can't find it: https://github.com/metanorma/isodoc/actions/runs/9020101255/job/24784607346

I must have overwritten the logs when I resubmitted the code. I'm about to submit a new update, which may trigger it again

opoudjis commented 6 months ago

Confirmed:

https://github.com/metanorma/isodoc/actions/runs/9044242039/job/24852701752

opoudjis commented 5 months ago

Is this fixed?

opoudjis commented 5 months ago

This is not fixed.

THIS MUST BE FIXED. I am releasing Metanorma, after a month delay, next Monday.

alexeymorozov commented 5 months ago

Confirmed:

https://github.com/metanorma/isodoc/actions/runs/9044242039/job/24852701752

I've released v0.7.7 of vectory. Now it works with this GHA. Now this workflow run has the same 3 fails which were before - not related to vectory.

@opoudjis Thank you for the GHA example, it helped to explore the issue.