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

Division by zero in invalid table (low prio) #704

Closed
JohannesMunk opened this Issue Oct 11, 2018 · 0 comments

Comments

2 participants
@JohannesMunk
Copy link

JohannesMunk commented Oct 11, 2018

I just stumbled over this.. Its my fault my algo should introduce missing table cells - so please don't loose any sleep over this. But maybe you want to check for a nonzero other_columns_contributions when trying to collect the widths of other columns. In this screwd example, wp raises a divison by zero exception.

<html>
<head>
	<meta charset='utf-8' />
	<style>
		.expand {width: 30%;}
	</style>
</head>
<body>
	<table>
		<tr>
			<th>A</th>
			<th class='expand'>B</th>
			<th>C</th>
		</tr>
		<tr>
			<td colspan='2'></td>
			<!--<td></td>-->
		</tr>
		<tr>
			<th class='expand'>A</th>
			<th>B</th>
			<th>C</th>
		</tr>
	</table>
</body>
</html>

crashes with:

I:\x3rdParty\Python
Traceback (most recent call last):
  File "I:\x3rdParty\Python\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "I:\x3rdParty\Python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\__main__.py", line 177, in <module>
    main()
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\__main__.py", line 173, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\__init__.py", line 198, in write_pdf
    font_config=font_config).write_pdf(
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\__init__.py", line 159, in render
    font_config)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\document.py", line 361, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\document.py", line 361, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\__init__.py", line 126, in layout_document
    context, root_box, html, cascaded_styles, computed_styles, pages))
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\pages.py", line 788, in make_all_pages
    i, context, root_box, html, cascaded_styles, computed_styles)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\pages.py", line 726, in remake_page
    page_number, page_state)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\pages.py", line 554, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 71, in block_level_layout_switch
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 125, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 495, in block_container_layout
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 71, in block_level_layout_switch
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 125, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 495, in block_container_layout
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 71, in block_level_layout_switch
    adjoining_margins)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\blocks.py", line 119, in block_box_layout
    context, box, (containing_block.width, containing_block.height))
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\tables.py", line 627, in table_wrapper_width
    auto_table_layout(context, wrapper, containing_block)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\tables.py", line 526, in auto_table_layout
    table_and_columns_preferred_widths(context, box, outer=False)
  File "I:\x3rdParty\Python\lib\site-packages\weasyprint\layout\preferred.py", line 473, in table_and_columns_preferred_widths
    ratio = 1 / len(other_columns_contributions)
ZeroDivisionError: division by zero
I:\xClients\Crown-Temp\WP-crashOnExpand>

It doesnt crash when the 2nd table gets the missing cell. Or when the expand class is removed.

@liZe liZe added the bug label Oct 21, 2018

@liZe liZe closed this in e49e204 Jan 3, 2019

@liZe liZe added this to the 45 milestone Jan 3, 2019

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Feb 21, 2019

py-weasyprint: Update to 45.
Version 45
----------

Released on 2019-02-20.

WeasyPrint now has a `code of conduct
<https://github.com/Kozea/WeasyPrint/blob/master/CODE_OF_CONDUCT.rst>`_.

A new website has been launched, with beautiful and useful graphs about speed
and memory use across versions: check `WeasyPerf
<https://kozea.github.io/WeasyPerf/index.html>`_.

Dependencies:

* Python 3.5+ is now needed, Python 3.4 is not supported anymore

Bug fixes:

* `798 <https://github.com/Kozea/WeasyPrint/pull/798>`_:
  Prevent endless loop and index out of range in pagination
* `767 <https://github.com/Kozea/WeasyPrint/issues/767>`_:
  Add a ``--quiet`` CLI parameter
* `784 <https://github.com/Kozea/WeasyPrint/pull/784>`_:
  Fix library loading on Alpine
* `791 <https://github.com/Kozea/WeasyPrint/pull/791>`_:
  Use path2url in tests for Windows
* `789 <https://github.com/Kozea/WeasyPrint/pull/789>`_:
  Add LICENSE file to distributed sources
* `788 <https://github.com/Kozea/WeasyPrint/pull/788>`_:
  Fix pending references
* `780 <https://github.com/Kozea/WeasyPrint/issues/780>`_:
  Don't draw patterns for empty page backgrounds
* `774 <https://github.com/Kozea/WeasyPrint/issues/774>`_:
  Don't crash when links include quotes
* `637 <https://github.com/Kozea/WeasyPrint/issues/637>`_:
  Fix a problem with justified text
* `763 <https://github.com/Kozea/WeasyPrint/pull/763>`_:
  Launch tests with Python 3.7
* `704 <https://github.com/Kozea/WeasyPrint/issues/704>`_:
  Fix a corner case with tables
* `804 <https://github.com/Kozea/WeasyPrint/pull/804>`_:
  Don't logger handlers defined before importing WeasyPrint
* `109 <https://github.com/Kozea/WeasyPrint/issues/109>`_,
  `748 <https://github.com/Kozea/WeasyPrint/issues/748>`_:
  Don't include punctuation for hyphenation
* `770 <https://github.com/Kozea/WeasyPrint/issues/770>`_:
  Don't crash when people use uppercase words from old-fashioned Microsoft
  fonts in tables, especially when there's an 5th column
* Use a `separate logger
  <https://weasyprint.readthedocs.io/en/latest/tutorial.htmllogging>`_ to
  report the rendering process
* Add a ``--debug`` CLI parameter and set debug level for unknown prefixed CSS
  properties
* Define minimal versions of Python and setuptools in setup.cfg

Documentation

* `796 <https://github.com/Kozea/WeasyPrint/pull/796>`_:
  Fix a small typo in the tutorial
* `792 <https://github.com/Kozea/WeasyPrint/pull/792>`_:
  Document no alignement character support
* `773 <https://github.com/Kozea/WeasyPrint/pull/773>`_:
  Fix phrasing in Hacking section
* `402 <https://github.com/Kozea/WeasyPrint/issues/402>`_:
  Add a paragraph about fontconfig error
* `764 <https://github.com/Kozea/WeasyPrint/pull/764>`_:
  Fix list of dependencies for Alpine
* Fix API documentation of HTML and CSS classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.