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

using 2 columns style in different levels of the HTML lead to IndexError #981

Closed
fabiobatalha opened this issue Oct 28, 2019 · 8 comments
Closed
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@fabiobatalha
Copy link

fabiobatalha commented Oct 28, 2019

A simple CSS change to change the text style to 2 columns lead the convertion to a IndexError.

Working Package:
2columns-working.zip

Failing Package:
2columns-failing.zip

The only difference between one and another is the css bellow:

.ref-list {
    columns: 2;
    column-gap: 0.5cm;
}

WeasyPrint Version: v50

Traceback :

  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/__init__.py", line 211, in write_pdf
    font_config=font_config).write_pdf(
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/__init__.py", line 168, in render
    font_config)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/document.py", line 393, in _render
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/document.py", line 393, in <listcomp>
    [Page(page_box, enable_hinting) for page_box in page_boxes],
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/__init__.py", line 126, in layout_document
    pages = list(make_all_pages(context, root_box, html, pages))
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 803, in make_all_pages
    page, resume_at = remake_page(i, context, root_box, html)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 742, in remake_page
    page_number, page_state)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/pages.py", line 553, in make_page
    positioned_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 510, in block_container_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 105, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/columns.py", line 130, in columns_layout
    adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 63, in block_level_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 77, in block_level_layout_switch
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 130, in block_box_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/blocks.py", line 376, in block_container_layout
    for line, resume_at in lines_iterator:
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 53, in iter_line_boxes
    absolute_boxes, fixed_boxes, first_letter_style)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 70, in get_next_linebox
    skip_stack = skip_first_whitespace(linebox, skip_stack)
  File "/home/fabiobatalha/.Envs/converter/lib/python3.6/site-packages/weasyprint/layout/inlines.py", line 210, in skip_first_whitespace
    result = skip_first_whitespace(box.children[index], next_skip_stack)
IndexError: tuple index out of range

@Tontyna
Copy link
Contributor

Tontyna commented Oct 29, 2019

Cannot reproduce the crash but I presume it's a duplicate of #953 and might be fixed by #956

@Tontyna
Copy link
Contributor

Tontyna commented Oct 29, 2019

Maybe it's another version of #984

@fabiobatalha
Copy link
Author

I'm testing this with #956

@fabiobatalha
Copy link
Author

The error is still there while testing with #956 and the master

@fabiobatalha
Copy link
Author

fabiobatalha commented Oct 29, 2019

I tried to isolate the snippet that is causing the error.

I figured out that a special character is one of the reasons to raise IndexError.

Use case 1 (Failling with indexError):

  • {collumn-span: all}
  • special character in Søraker
<!DOCTYPE html>
<html>
<style>
.article {
    font-family: Arial;
    font-size: 15px;
}

.ref-list {
    columns: 2;
    column-gap: 0.5cm;
}

.ref-list .title {
    column-span: all;
    border-bottom: solid 2px gray;
    text-transform: uppercase;
}
</style>
</head>
<body>
    <div class="document">
        <div class="article">
            <div class="body_back">
                <div class="back">
                    <div class="ref-list">
                        <div class="title">Références bibliographiques</div>
                        <ul>
                            <li class="ref">A<small>rlegi</small>, R. et M. T<small>eschl</small> (2014), « Conflict, Commitment and Well-Being » <i>in</i><small>Søraker</small>, J. H., J. W. <small>van</small><small>der</small> R<small>ijt</small>, J. B<small>oer</small>, P. H. W<small>ong</small> et P. B<small>rey</small> (éds), <i>Well-Being in Contemporary Society</i>, Cham, Springer.</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

Use case 2 (Success):

  • {collumn-span: all}
  • removed the special character in Søraker
<!DOCTYPE html>
<html>
<style>
.article {
    font-family: Arial;
    font-size: 15px;
}

.ref-list {
    columns: 2;
    column-gap: 0.5cm;
}

.ref-list .title {
    column-span: all;
    border-bottom: solid 2px gray;
    text-transform: uppercase;
}
</style>
</head>
<body>
    <div class="document">
        <div class="article">
            <div class="body_back">
                <div class="back">
                    <div class="ref-list">
                        <div class="title">Références bibliographiques</div>
                        <ul>
                            <li class="ref">A<small>rlegi</small>, R. et M. T<small>eschl</small> (2014), « Conflict, Commitment and Well-Being » <i>in</i><small>Sraker</small>, J. H., J. W. <small>van</small><small>der</small> R<small>ijt</small>, J. B<small>oer</small>, P. H. W<small>ong</small> et P. B<small>rey</small> (éds), <i>Well-Being in Contemporary Society</i>, Cham, Springer.</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

Use case 3 (Success):

  • removed {collumn-span: all}
  • special character in Søraker
<!DOCTYPE html>
<html>
<style>
.article {
    font-family: Arial;
    font-size: 15px;
}

.ref-list .title {
    column-span: all;
    border-bottom: solid 2px gray;
    text-transform: uppercase;
}
</style>
</head>
<body>
    <div class="document">
        <div class="article">
            <div class="body_back">
                <div class="back">
                    <div class="ref-list">
                        <div class="title">Références bibliographiques</div>
                        <ul>
                            <li class="ref">A<small>rlegi</small>, R. et M. T<small>eschl</small> (2014), « Conflict, Commitment and Well-Being » <i>in</i><small>Søraker</small>, J. H., J. W. <small>van</small><small>der</small> R<small>ijt</small>, J. B<small>oer</small>, P. H. W<small>ong</small> et P. B<small>rey</small> (éds), <i>Well-Being in Contemporary Society</i>, Cham, Springer.</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

Conclusion

The combination of column-span and the special character is causing WeasyPrint to crash in IndexError Exception.

Comments

It is not clear to me why a special character should be responsible for this error.

@Tontyna
Copy link
Contributor

Tontyna commented Oct 29, 2019

It is not clear to me why a special character should be responsible for this error.

In the past there were all sorts of strange errors with strange characters... and there were strange errors with 'windowish' fonts on nix systems. My OS is Windows. That might be the reason why I cannot reproduce the IndexError with your snippet.

I think it's column-span: all that disarranges (under certain conditions not yet fully researched) the skip_stack. Similar conditions like the ones that are fixed with #956 and its predecessors. Complicated line-breaks...

@Tontyna
Copy link
Contributor

Tontyna commented Oct 30, 2019

Ah, finally your snippet crashes on my computer, too - WeasyPrint v50 and current master branch. But with a different error: IndexError: list index out of range. Furthermore it's neither prevented by removing the ø nor the column-span:all.

As expected: My crash is fixed by #956.

@liZe
Copy link
Member

liZe commented Nov 8, 2019

As expected: My crash is fixed by #956.

It is for me too. Let's close this.

@liZe liZe closed this as completed Nov 8, 2019
@liZe liZe added the crash Problems preventing documents from being rendered label Nov 8, 2019
@liZe liZe added this to the 51 milestone Nov 8, 2019
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

3 participants