Bug #106094
closedException in ImageProcessingInstructions if calculated maxWidth is float
100%
Description
To reproduce:
Add a svg image with eg. 400 x 400 px (example image attached) as page thumbnail (via page properties using EXT:bootstrap_package). Add a menu content element "cards from subpages" to another page and select the parent page of the previous added page with the svg page thumbnail.
Open the page with the menu and you will get the following exception:
```
TYPO3\CMS\Core\Imaging\ImageProcessingInstructions::__construct(): Argument #1 ($width) must be of type int, float given, called in /var/www/html/vendor/typo3/cms-core/Classes/Imaging/ImageProcessingInstructions.php on line 231
```
The cause is a missing int cast at the returned width and height values of the static method ImageProcessingInstructions::fromCropScaleValues.
This problem can easily fixed by changing line 231-235 from this:
```
return new self(
width: $width,
height: $height,
cropArea: $cropArea,
);
```
to this:
```
return new self(
width: (int)$width,
height: (int)$height,
cropArea: $cropArea,
);
```
Files
Updated by Garvin Hicking about 1 month ago
- Status changed from New to Needs Feedback
Hi!
Due to another issue I looked at this today. Actually, all of the places already have (int) casts in place for calculation of width and height, so I wonder where/how exactly a float is introduced.
I could only see that happenin in case an option like "maxWidth"/"minWidth" or "maxHeight"/"minWidth" would be specified with a float value.
Could you present the whole stack trace please?
Regards,
Garvin
Updated by Alexander Grein about 1 month ago
No, they don't have all int casts.
Take eg. a look at line 181:
$width = $options['maxWidth'];
and line 187:
$height = $options['maxHeight'];
and line 194:
$width = $options['minWidth'];
and line 200:
$height = $options['minHeight'];
In all cases, there is no int-cast afterwards, unless their values are “0” or $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_allowUpscaling'] == true and the width or height is larger than the cropArea width or height.
This is by far not always the case.
Updated by Garvin Hicking about 1 month ago
Yes, we would need to check if maybe bootstrap_package passes these options as floats, hence asking for the full stacktrace to see where they come from. Ideally we shouldnt fix a symtpom but a cause.
Updated by Alexander Grein about 1 month ago
· Edited
Line 120: public static function fromCropScaleValues(int $incomingWidth, int $incomingHeight, int|string $width, int|string $height, array $options): self
This method is a public (static) not internal marked method, where the $options attribute has only to be an array.
Why should we search for the cause outside?
At the beginning of this method, there is a call to streamlineOptions. Maybe this would be a good place to make sure the critical options become integers if set?
This method (streamlineOptions) has this doc comment:
/** * @return array{ * maxWidth?: int, * maxHeight?: int, * minWidth?: int, * minHeight?: int, * crop?: Area, * } */
But there is no int casting anywhere inside.
Updated by Alexander Grein about 1 month ago
- File TYPO3 Exception.html TYPO3 Exception.html added
Updated by Garvin Hicking about 1 month ago
Let's investigate with the stack trace and where it comes from, thank you.
Of course you're free to propose any patch you deem fit, but I personally always want to know where an issue arises from.
Also, please let's be constructive and appreciative to each other, I feel like I need to defend myself when all I want is to help.
Updated by Alexander Grein about 1 month ago
· Edited
I like to do that too. I'm sorry if you got a different feeling.
I was just a bit annoyed, because I already created a patch for the site where I discovered this problem and I had to revert it first.
After doing this, I first thought the problem was magically gone, but after clearing the processed images cache it pops up again.
Next problem was the huge stack trace, where I had no idea how to add it to this tracker.
Another thought that just popped into my head:
Since the private method “streamlineOptions” is only used once and the "fromCropScaleValues" method needs integer values in the end, the proposed solution seemed the most efficient to me.
Maybe also interesting:
The svg image (attached) that creates the problem has a width of 400. The output of the bootstrap_package content element "cards from subpages" is used in the main column of the "2 columns layout with left side sub navigation". The settings inside this content element are alignment left with 4 columns.
Updated by Gerrit Code Review about 1 month ago
- Status changed from Needs Feedback to Under Review
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88206
Updated by Gerrit Code Review about 1 month ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88206
Updated by Gerrit Code Review about 1 month ago
Patch set 6 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88206
Updated by Gerrit Code Review about 1 month ago
Patch set 1 for branch 13.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/88238
Updated by Garvin Hicking about 1 month ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 5b3efef806e0834dcaaeb25f2a1ddb951b1c1bfe.
Updated by Garvin Hicking about 1 month ago
Hi Alexander,
you may have seen the patch got merged more quickly than I thought. I did rework the patch to add (int) casting like you proposed. Maybe you could check it out and see if that works out for you this way?
Regards,
Garvin
Updated by Garvin Hicking 17 days ago
- Precedes Bug #106329: ImageProcessingInstructions misses an integer casting for one scenario added