fix: Prevent DivisionByZeroError in BaseHandler::reproportion() with float 0.0#10319
fix: Prevent DivisionByZeroError in BaseHandler::reproportion() with float 0.0#10319gr8man wants to merge 3 commits into
Conversation
…eHandler::reproportion() and add tests
| $w = (int) $this->width; | ||
| $h = (int) $this->height; | ||
|
|
||
| if (! is_numeric($this->width) || ! is_numeric($this->height) || $origW === 0 || $origH === 0 || ($w === 0 && $h === 0)) { |
There was a problem hiding this comment.
is_numeric() is much broader than ctype_digit(). 0.0 should be checked explicitly.
| $expectedWidth = $handler->getWidth(); | ||
| $expectedHeight = $handler->getHeight(); | ||
|
|
||
| $method = new ReflectionMethod($handler::class, 'reproportion'); |
There was a problem hiding this comment.
Please use one of the ReflectionHelper methods instead: https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/Test/ReflectionHelper.php
|
I should have checked this earlier, but it looks like the PHPDoc for Since |
Description
This PR fixes a potential
DivisionByZeroErrorinsideBaseHandler::reproportion()when processing image resizing operations where dimensions (origWidthororigHeight) might evaluate to0.0(float) or when provided dimensions are invalid.Previously, the strict comparison check
=== 0on float0.0allowed the execution to pass through the initial guard clause, causing a crash during proportion calculations.Changes:
reproportion()to safely cast inputs tointand centralize dimension validation.is_numeric()to ensure both provided and original dimensions are mathematically valid.testReproportionWithFloatZeroinBaseHandlerTestutilizing Reflection to directly test the protected method's early return behavior without side effects.Checklist: