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

ZeroDivisionError when rendering code tag #1499

Closed
antirais opened this issue Nov 17, 2021 · 1 comment
Closed

ZeroDivisionError when rendering code tag #1499

antirais opened this issue Nov 17, 2021 · 1 comment
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@antirais
Copy link

antirais commented Nov 17, 2021

WeasyPrint fails to render following document:

<!DOCTYPE html>
<html lang="et">
<head>
    <title>PoC</title>
</head>
<body>
    <code>test</code>
</body>
</html>

poc

$ weasyprint test.html test.pdf
Traceback (most recent call last):
  File "/home/anti/.pyenv/versions/crg/bin/weasyprint", line 8, in <module>
    sys.exit(main())
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/__main__.py", line 214, in main
    html.write_pdf(output, **kwargs)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/__init__.py", line 180, in write_pdf
    self.render(
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/document.py", line 1160, in write_pdf
    page.paint(stream, scale=scale)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/document.py", line 769, in paint
    draw_page(self._page_box, stream)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 69, in draw_page
    draw_stacking_context(stream, stacking_context)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 182, in draw_stacking_context
    draw_stacking_context(stream, child_context)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 177, in draw_stacking_context
    draw_inline_level(
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 960, in draw_inline_level
    draw_inline_level(
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 957, in draw_inline_level
    draw_text(
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 985, in draw_text
    draw_first_line(stream, textbox, text_overflow, block_ellipsis, x, y)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/draw.py", line 1090, in draw_first_line
    font = stream.add_font(font_hash, file_content, pango_font, index)
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/document.py", line 217, in add_font
    self._document.fonts[font_hash] = Font(
  File "/home/anti/.pyenv/versions/crg/lib/python3.9/site-packages/weasyprint/document.py", line 92, in __init__
    pango.pango_font_metrics_get_ascent(pango_metrics) /
ZeroDivisionError: division by zero

version info

$ weasyprint -i
System: Linux
Machine: x86_64
Version: #1 SMP Fri, 12 Nov 2021 19:04:00 +0000
Release: 5.10.79-1-lts

WeasyPrint version: 53.4
Python version: 3.9.7
Pydyf version: 0.1.2
Pango version: 14810

Works fine with 52.5 version:

$ weasyprint -i
System: Linux
Machine: x86_64
Version: #1 SMP Fri, 12 Nov 2021 19:04:00 +0000
Release: 5.10.79-1-lts

WeasyPrint version: 52.5
Python version: 3.9.7
Cairo version: 11704
Pango version: 14810
CairoSVG version: 2.5.2
@liZe liZe closed this as completed in 80b88db Nov 29, 2021
@liZe
Copy link
Member

liZe commented Nov 29, 2021

Hello!

Thanks for this bug report.

This problem shouldn’t happen, unless you use a very small font size (< 1 / 1024 px), or there’s a problem with the font used (probably the default monospace font in your case).

At least, now, we don’t crash.

But… Your text will probably not be displayed. Maybe installing monospace fonts will help. If you can’t find a solution, don’t hesitate to add a comment here.

@liZe liZe added bug Existing features not working as expected crash Problems preventing documents from being rendered and removed bug Existing features not working as expected labels Nov 29, 2021
@liZe liZe added this to the 54.0 milestone Nov 29, 2021
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