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

Infinite loops when white-space: nowrap tags have inner text starting with a slash #586

Closed
samdmarshall opened this issue Mar 8, 2018 · 1 comment
Labels
bug Existing features not working as expected crash Problems preventing documents from being rendered
Milestone

Comments

@samdmarshall
Copy link

samdmarshall commented Mar 8, 2018

I am running into an issue where weasyprint seems to get stuck/hung when trying to generate a pdf of a local or remote html file (https://pewpewthespells.com/blog/sparse_sdks.html). I had installed weasyprint via pip3, and it seems to work fine on a number of other html pages generated from markdown->html via pandoc, but not this one in particular. I thought it might be related to the specific html generated in this page so I ran it against tidy and only got back the following:

line 633 column 1 - Warning: <center> element removed from HTML5

So I am at a bit of a loss as to what is causing weasyprint to get stuck on this page in particular.

Command used to generate the html page:

pandoc 
  --from markdown+grid_tables 
  --to html5 
  --include-in-header "header.html" 
  --highlight-style pygments 
  --email-obfuscation references 
  sparse_sdks.md 
  --output "sparse_sdks.html"

When weasyprint is executed and proceeds to get stuck being hung and is killed via local interrupt this is the traceback I get:

Traceback (most recent call last):
  File "/usr/local/bin/weasyprint", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__main__.py", line 177, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__init__.py", line 182, in write_pdf
    font_config=font_config).write_pdf(
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__init__.py", line 143, in render
    font_config)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/document.py", line 326, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/document.py", line 326, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/__init__.py", line 55, in layout_document
    context, root_box, html, cascaded_styles, computed_styles))
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/pages.py", line 601, in make_all_pages
    context, root_box, page_type, resume_at, page_number)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/pages.py", line 520, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 638, in block_container_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 638, in block_container_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    for line, resume_at in lines_iterator:
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 51, in iter_line_boxes
    device_size, absolute_boxes, fixed_boxes, first_letter_style)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 108, in get_next_linebox
    waiting_floats, line_children=[])
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 727, in split_inline_box
    line_placeholders, waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 600, in split_inline_level
    waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 727, in split_inline_box
    line_placeholders, waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 577, in split_inline_level
    context, box, max_x - position_x, skip)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 915, in split_text_box
    text, box.style, context, available_width, box.justification_spacing)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 959, in split_first_line
    text, style, context, max_width, justification_spacing)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 849, in create_layout
    layout = Layout(context, style.font_size, style)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 637, in __init__
    'cairo_t *', cairo_dummy_context._pointer)),
KeyboardInterrupt
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 47, in apport_excepthook
    try:
KeyboardInterrupt

Original exception was:
Traceback (most recent call last):
  File "/usr/local/bin/weasyprint", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__main__.py", line 177, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__init__.py", line 182, in write_pdf
    font_config=font_config).write_pdf(
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/__init__.py", line 143, in render
    font_config)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/document.py", line 326, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/document.py", line 326, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/__init__.py", line 55, in layout_document
    context, root_box, html, cascaded_styles, computed_styles))
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/pages.py", line 601, in make_all_pages
    context, root_box, page_type, resume_at, page_number)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/pages.py", line 520, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 638, in block_container_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 638, in block_container_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 83, in block_level_layout
    adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 111, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    for line, resume_at in lines_iterator:
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 51, in iter_line_boxes
    device_size, absolute_boxes, fixed_boxes, first_letter_style)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 108, in get_next_linebox
    waiting_floats, line_children=[])
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 727, in split_inline_box
    line_placeholders, waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 600, in split_inline_level
    waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 727, in split_inline_box
    line_placeholders, waiting_floats, line_children)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 577, in split_inline_level
    context, box, max_x - position_x, skip)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/layout/inlines.py", line 915, in split_text_box
    text, box.style, context, available_width, box.justification_spacing)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 959, in split_first_line
    text, style, context, max_width, justification_spacing)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 849, in create_layout
    layout = Layout(context, style.font_size, style)
  File "/usr/local/lib/python3.5/dist-packages/weasyprint/text.py", line 637, in __init__
    'cairo_t *', cairo_dummy_context._pointer)),
KeyboardInterrupt

Weasyprint version info:

WeasyPrint version 0.42.2

OS Version Info:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial

running on: Microsoft Windows [Version 10.0.16299.248] via the WSL.

@liZe
Copy link
Member

liZe commented Mar 8, 2018

The problem comes from white-space: nowrap tags with inner text starting with a slash (code tags with paths in your document).

I'm always impressed by all these strange new corner cases.

@liZe liZe changed the title weasyprint gets stuck trying to process pandoc generated html page Infinite loops when white-space: nowrap tags have inner text starting with a slash Mar 8, 2018
@liZe liZe added crash Problems preventing documents from being rendered bug Existing features not working as expected labels Mar 8, 2018
@liZe liZe added this to the 43 milestone Mar 8, 2018
@liZe liZe closed this as completed in 3b52fb0 Mar 10, 2018
liZe added a commit that referenced this issue Mar 27, 2018
Fix #586.

For some reason I don't really understand, stripping trailing spaces that would
make the line too long can't be optimized when the space is at the end of the
block. Returning None instead of the index of the last letter should be
possible, but it breaks the rendering when the first letter of the next line
box starts with a character that doesn't allow line breaks after spaces (many
punctuation characters for example) and that doesn't allow line wrap.

This change shouldn't be harmful, as the removed code lines were just cleaning
the resume_at value without changing the logic of line breaking. I suppose that
there's a bug somewhere else.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants