Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute positionned SVG with no width attribute crashes #1050

Closed
gutard opened this issue Feb 4, 2020 · 2 comments
Closed

Absolute positionned SVG with no width attribute crashes #1050

gutard opened this issue Feb 4, 2020 · 2 comments
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@gutard
Copy link

gutard commented Feb 4, 2020

Version : 51 (but older versions and master seem affected too)

Backtrace :

  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/__init__.py", line 171, in render
    font_config, counter_style)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/document.py", line 398, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/document.py", line 398, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/__init__.py", line 123, in layout_document
    pages = list(make_all_pages(context, root_box, html, pages))
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/pages.py", line 800, in make_all_pages
    page, resume_at = remake_page(i, context, root_box, html)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/pages.py", line 739, in remake_page
    page_number, page_state)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/pages.py", line 550, in make_page
    positioned_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 60, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 74, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 127, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 503, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 60, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 74, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 127, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 503, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 60, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 74, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 127, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 503, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 60, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 74, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 127, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 329, in block_container_layout
    context, child, box, absolute_boxes, fixed_boxes)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/float.py", line 69, in float_layout
    adjoining_margins=None)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 654, in block_container_layout
    absolute_layout(context, absolute_box, new_box, fixed_boxes)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/absolute.py", line 269, in absolute_layout
    absolute_box_layout(context, box, containing_block, fixed_boxes))
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/absolute.py", line 301, in absolute_box_layout
    new_box = absolute_replaced(context, box, containing_block)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/absolute.py", line 310, in absolute_replaced
    inline_replaced_box_width_height(box, containing_block)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/inlines.py", line 417, in inline_replaced_box_width_height
    replaced_box_width.without_min_max(box, containing_block)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/inlines.py", line 363, in replaced_box_width
    block_level_width(box, containing_block)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/min_max.py", line 17, in wrapper
    result = function(box, *args)
  File "/home/geotrekadmin/Geotrek-admin/lib/src/Weasyprint/weasyprint/layout/blocks.py", line 168, in block_level_width
    cb_width = containing_block.width
AttributeError: 'tuple' object has no attribute 'width'

The value of containing_block is (52.913385826771645, 158.74015748031496, 56.69291338582677, 56.69291338582677). This value is computed in function absolute_box_layout() line 286 : containing_block = cb_x, cb_y, cb_width, cb_height. I suppose it should be an instance of BlockBox instead.

@liZe liZe added the crash Problems preventing documents from being rendered label Feb 4, 2020
@gutard
Copy link
Author

gutard commented Mar 12, 2020

I can reproduce with just two simple files.

foo.html:

<html>
  <body>
    <img src="foo.svg" style="position: absolute;">
  </body>
</html>

foo.svg:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   viewBox="0 0 210 297">
</svg>

HTML is just an <img> tag with absolute positionning. It crashes when SVG file has no width attribute in <svg> tag. It works if I add this attribute.

@gutard gutard changed the title AttributeError: 'tuple' object has no attribute 'width' Absolute positionned SVG with no width attribute crashes Mar 12, 2020
@liZe liZe closed this as completed in fe7fd1c Mar 14, 2020
@liZe liZe added this to the 52 milestone Mar 14, 2020
@liZe
Copy link
Member

liZe commented Mar 14, 2020

Thanks a lot for the samples, it was really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants