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

IndexError when bulding fonts dictionary for PDF version 1.4 #1907

Closed
catcombo opened this issue Jul 11, 2023 · 4 comments · Fixed by #1908
Closed

IndexError when bulding fonts dictionary for PDF version 1.4 #1907

catcombo opened this issue Jul 11, 2023 · 4 comments · Fixed by #1908
Labels
bug Existing features not working as expected
Milestone

Comments

@catcombo
Copy link
Contributor

I'm using weasyprint version 59. I found the bug when trying to render a PDF with the PDF version 1.4. The problem is in the following code https://github.com/Kozea/WeasyPrint/blob/master/weasyprint/pdf/fonts.py#L118-L123

if pdf.version <= b'1.4':
    cids = sorted(font.widths)
    padded_width = int(ceil(cids[-1] / 8))
    bits = ['0'] * padded_width * 8
    for cid in cids:
        bits[cid] = '1'

In my case cids contains [3, 49, 58, 68, 72, 73, 74, 76, 79, 81, 82, 86, 88]. So the cids[-1] is 88 which can be divided by 8 without a reminder. This causes the problems in the code after that. padded_width value will be 11, bits length is 88, and in the loop there will be an IndexError when trying to set the last bit when cid = 88.

@liZe
Copy link
Member

liZe commented Jul 12, 2023

Thanks a lot for the bug report and the pull request!

@liZe liZe added the bug Existing features not working as expected label Jul 12, 2023
@chadcasey
Copy link

This still fails for me using the brew-installed version, v63.0

@liZe
Copy link
Member

liZe commented Nov 4, 2024

This still fails for me using the brew-installed version, v63.0

The original bug has been fixed, so your problem should be different. Could you please share an example to reproduce your bug in a new issue?

@chadcasey
Copy link

This still fails for me using the brew-installed version, v63.0

The original bug has been fixed, so your problem should be different. Could you please share an example to reproduce your bug in a new issue?

Thank you for the quick response! I've moved on from trying to use 1.4 (time constraints), but if I have time to get back to it I will open a new issue.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants