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

Zero-division error #2306

Closed
Andlet95 opened this issue Nov 19, 2024 · 3 comments
Closed

Zero-division error #2306

Andlet95 opened this issue Nov 19, 2024 · 3 comments
Labels
crash Problems preventing documents from being rendered

Comments

@Andlet95
Copy link

There is a chance for a zero-division error in weasyprint/layout/table.py this line

A few lines prior, it checks for equality between the lists, but it doesn't account for upper_guess - lower_guess becoming a list that sums to zero

e.g.:

upper_guess: [126.9765625, 492.49902874615935, 330.0644425076814, 492.49902874615935]
lower_guess: [126.9765625, 507.35531887654616, 300.3518622469078, 507.35531887654616]
added_widths: [0.0, -14.85629013038681, 29.71258026077362, -14.85629013038681]

This is my printout, which In this instance, sum(added_widths becomes zero, and we have a zero-division.

I did some testing, and changed this line from if assignable_width <= sum(max_content_guess): to if assignable_width < sum(max_content_guess): which helped in my case. I have a feeling that's not safeguarding the zero-division though, but only sidestepping the issue for my use-case.

I tested this both with python-weasyprint-62.3-2 using the installation on my laptop and weasyprint-63 using a virtual env

I can't share the html file I'm trying to convert, but if there's a way I can figure out what lines is causing this, I can see if there's sensitive information and possibly share that part.

@liZe
Copy link
Member

liZe commented Nov 19, 2024

Thanks for the report. We already discussed about it in #2276 and got a document to reproduce, but we didn’t take the time yet to fix it and add a non-regression test.

@liZe
Copy link
Member

liZe commented Nov 19, 2024

Here’s a sample to reproduce:

<table style="font-family: DejaVu Serif">
  <thead>
    <tr>
      <th colspan="2">aaaaaaaaaaaaaaaaaa</th>
    </tr>
    <tr>
      <th style="width:80px"></th>
      <th style="width:80px">rrrrr</th>
    </tr>
  </thead>
</table>

@liZe
Copy link
Member

liZe commented Nov 19, 2024

I did some testing, and changed this line from if assignable_width <= sum(max_content_guess): to if assignable_width < sum(max_content_guess): which helped in my case.

I think that this change makes sense: if the assignable width equals to the max-content guess, and the added widths can be 0. In this case, we can use the max-content guess values, as done in the else part.

@liZe liZe added the crash Problems preventing documents from being rendered label Nov 19, 2024
@liZe liZe closed this as completed in a2e0bbd Nov 19, 2024
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