Skip to content

Avoid ZeroDivisionError when a component is wider than the page - #29

Open
fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:guard-zero-division
Open

fdegros wants to merge 1 commit into
pjkundert:masterfrom
fdegros:guard-zero-division

Conversation

@fdegros

@fdegros fdegros commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

When a card or Paper Wallet is wider (or taller) than the printable page, layout_components computed 0 components per page, and page_xy then divided by zero.

This lays out at least 1 component per page in each direction instead; the component simply overflows the page margins. It's the failure behind #10 (--paper a4 with the wider half-, third- and quarter-letter formats): your fix for the sizes removed the common cause, and this removes the crash for any other oversized component.

  • Change: slip39/layout/components.py, 2 lines (max( 1, ... )).
  • Test: test_layout_components_oversize in slip39/output_test.py; it fails with the ZeroDivisionError on current master and passes with this change.
  • pytest (without the invoice/communications tests, which need optional packages): 42 passed, 4 skipped; recovery_test.py::test_dft_smoke fails on Python 3.14 when numpy isn't installed (the pure-Python idft fallback), with or without this change.

When a card or wallet is wider (or taller) than the printable page, layout_components
computed 0 components per page, and page_xy divided by zero.  Lay out at least 1
component per page in each direction instead; the component simply overflows the
page margins.

See pjkundert#10 (the error reported with --paper a4 and the wider half-, third- and
quarter-letter formats).

This branch has not been deployed

No deployments
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.

1 participant