Project

General

Profile

Actions

Bug #106094

closed

Exception in ImageProcessingInstructions if calculated maxWidth is float

Added by Alexander Grein about 2 months ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
Image Generation / GIFBUILDER
Start date:
2025-02-06
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
13
PHP Version:
8.3
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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

Extension.svg (1.16 KB) Extension.svg Alexander Grein, 2025-02-06 09:18
TYPO3 Exception.html (256 KB) TYPO3 Exception.html Alexander Grein, 2025-02-14 15:07

Related issues 1 (0 open1 closed)

Precedes TYPO3 Core - Bug #106329: ImageProcessingInstructions misses an integer casting for one scenarioResolvedGarvin Hicking2025-02-142025-02-14

Actions
Actions #1

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

Actions #2

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.

Actions #3

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.

Actions #4

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.

Actions #6

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.

Actions #7

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.

Actions #8

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

Actions #9

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

Actions #10

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

Actions #11

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

Actions #12

Updated by Garvin Hicking about 1 month ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #13

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

Actions #14

Updated by Garvin Hicking 17 days ago

  • Precedes Bug #106329: ImageProcessingInstructions misses an integer casting for one scenario added
Actions

Also available in: Atom PDF