Skip to content

fix: Prevent DivisionByZeroError in BaseHandler::reproportion() with float 0.0#10319

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix-reproportion-division-by-zero
Open

fix: Prevent DivisionByZeroError in BaseHandler::reproportion() with float 0.0#10319
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix-reproportion-division-by-zero

Conversation

@gr8man

@gr8man gr8man commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Description
This PR fixes a potential DivisionByZeroError inside BaseHandler::reproportion() when processing image resizing operations where dimensions (origWidth or origHeight) might evaluate to 0.0 (float) or when provided dimensions are invalid.

Previously, the strict comparison check === 0 on float 0.0 allowed the execution to pass through the initial guard clause, causing a crash during proportion calculations.

Changes:

  • Refactored reproportion() to safely cast inputs to int and centralize dimension validation.
  • Added strict checks via is_numeric() to ensure both provided and original dimensions are mathematically valid.
  • Introduced testReproportionWithFloatZero in BaseHandlerTest utilizing Reflection to directly test the protected method's early return behavior without side effects.

Checklist:

  • Securely signed commits
  • Component(s) with PHPdoc fully completed
  • Unit testing, with >80% coverage
  • User guide updated (if applicable)

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