Skip to content

texttotext: restore the default tab width instead of just logging it - #283

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-texttotext-zero-tab-width-fpe
Oct 12, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
ManasBagul23:fix-texttotext-zero-tab-width-fpe

Conversation

@ManasBagul23

Copy link
Copy Markdown
Contributor

Fixes #180

cfFilterTextToText() parsed TabWidth/tab-width straight into tab_width via atoi(), then only used the validity check (tab_width <= 0 || tab_width > num_columns - 1) to pick which debug message to log — neither branch ever reset tab_width itself. The debug message claims "use default" but nothing did; an explicit TabWidth=0 (or any non-positive value) left tab_width at 0 all the way to the character loop, where column % tab_width is evaluated for every tab character in the document and divides by zero.

Reset tab_width to the documented default (8, the same value the variable is initialized to) when the validity check fails, instead of only logging that it would be. Also fixes the less severe half of the same check (tab_width > num_columns - 1 was flagged invalid but likewise never clamped).

Verification: extracted the atoi-and-validate logic and the vulnerable modulo into a standalone reproduction: TabWidth=0 through the unfixed validation crashes before anything is printed (the division by zero); through the fixed validation, tab_width is restored to 8 and the modulo completes normally.

cfFilterTextToText() parsed TabWidth/tab-width straight into tab_width
via atoi(), then only used the validity check (tab_width <= 0 ||
tab_width > num_columns - 1) to pick which debug message to log --
neither branch ever reset tab_width itself. The debug message claims
'use default' but nothing did; an explicit TabWidth=0 (or any
non-positive value) left tab_width at 0 all the way to the character
loop, where 'column % tab_width' is evaluated for every tab character
in the document and divides by zero.

Reset tab_width to the documented default (8, the same value the
variable is initialized to) when the validity check fails, instead of
only logging that it would be. Also fixes the less severe half of the
same check (tab_width > num_columns - 1 was flagged invalid but
likewise never clamped).

Verified by extracting the atoi-and-validate logic and the vulnerable
modulo into a standalone reproduction: TabWidth=0 through the
unfixed validation crashes before anything is printed (the division by
zero); through the fixed validation, tab_width is restored to 8 and
the modulo completes normally.

Fixes OpenPrinting#180.
Copilot AI balanced review requested due to automatic review settings October 12, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tillkamppeter
tillkamppeter merged commit 3daf8bd into OpenPrinting:master Oct 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

texttotext: accepted zero tab width causes division by zero

3 participants