Skip to content

Infinite loop in fill_textbox #4400

Closed
Closed
@jotaf98

Description

@jotaf98

Description of the bug

Hi, first of all, thanks for a great library!

I found an infinite loop condition when calling Writer.fill_textbox due to a bug in utils.py, where the correct counter for loop exit is not used.

The fix is simple, lines 4619-4620 in this file should read

            if n == 0:
                break

instead of if len(words) == 0.

How to reproduce the bug

Minimal script to reproduce:

import fitz

page = fitz.Document().new_page()
writer = fitz.TextWriter(page.rect)

text = '111111111'

writer.fill_textbox(rect=fitz.Rect(0, 0, 100, 20), pos=(80, 0), text=text, fontsize=8)

# this line will never be reached, as the above one enters an infinite loop

PyMuPDF version

1.25.4

Operating system

Windows

Python version

3.13

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions