Issue Bug Closed

#110076PHP Warning "Undefined array key" in ImageProcessingInstructions::streamlineOptions() when the "crop" option is an empty string

Andreas Stephan 06/18/26, 08:52 updated 06/26/26, 11:55

Description

Affected: TYPO3 13.4.32

Problem

Processing an image with an empty crop option ( 'crop' => '' ) makes ImageProcessingInstructions::streamlineOptions() emit three PHP warnings:

PHP Warning: Undefined array key 1/2/3 in .../Imaging/ImageProcessingInstructions.php line 338

With a target width but no height, the same empty crop instead throws a fatal Division by zero at line 174.

Root cause

streamlineOptions() guards the crop handling with isset($options['crop']) , which is true for an empty string. json_decode('') is falsy, so execution reaches:

[$offsetLeft, $offsetTop, $newWidth, $newHeight] = explode(',', $options['crop'], 4); // line 338

explode(',', '', 4) returns a single element → indexes 1/2/3 are undefined (the warnings) and an Area(0, 0, 0, 0) is built. That area is not dropped by the following isEmpty() check, because Area::isEmpty() only matches the full-image area:

return $this->x === 0.0 && $this->y === 0.0 && $this->width === 1.0 && $this->height === 1.0;

So the zero-width area reaches fromCropScaleValues() (line 134) and becomes the divisor at line 174 → Division by zero.

The sibling method getConfigurationForImageCropScaleMask() (line 393) guards the identical explode with a truthy check ( if ($configuration['crop'] ?? null) ), which already skips an empty string — so the two paths are inconsistent.

Why an empty crop is a real input

sys_file_reference.crop stays empty unless it is filled in via the backend image-cropping field (TCA type imageManipulation ). Programmatic creation therefore leaves it empty — e.g. an importer that builds a \TYPO3\CMS\Extbase\Domain\Model\FileReference and persists it via Extbase, as that model has no crop property. The empty value then flows into image processing, e.g. via ContentObjectRenderer::imageLinkWrap() , whose configuration sets crop.data = file:current:crop .

Reproduction (verified on 13.4.33 / PHP 8.4)

use TYPO3\CMS\Core\Resource\ProcessedFile;

$file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, ['width' => 100, 'height' => 80, 'crop' => '']);
// -> 3x "Undefined array key" (line 338)

$file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, ['width' => 100, 'crop' => '']);
// -> fatal "Division by zero" (line 174)

Expected

An empty crop string should be treated as “no crop”, without warnings or errors.

Suggested fix

In streamlineOptions (), treat an empty crop as absent — e.g. guard with !empty($options['crop']) instead of isset(...) , matching the sibling method. Optionally harden both explode() calls with a count(...) === 4 check.

Reviews 3

History 912

  1. Garvin Hicking commented and changed category status New Needs Feedback <span data-processor="relativetime" data-value="2026-06-18T11:17:37+00:00" > 06/18/26, 11:17 </span>

    Hi!

    Can you give an actually reproducible example for this? Usually the core should guard empty crops to remove them from the config array. Custom code should also do that.

    Regards,
    Garvin

  2. Andreas Stephan commented <span data-processor="relativetime" data-value="2026-06-18T12:48:29+00:00" > 06/18/26, 12:48 </span>

    Hi Garvin, thanks for looking into it!

    Self-contained reproduction — no file or frontend needed, since fromCropScaleValues() is public static and calls streamlineOptions() internally (TYPO3 13.4.32, PHP 8.4):

    1) Create a simple PHP file at the root of your project (e.g. crop-test.php )

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    require __DIR__ . '/vendor/autoload.php';
    
    // the flag only isolates the warning from the later scaling math in a bare script
    $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_allowUpscaling'] = true;
    
    \TYPO3\CMS\Core\Imaging\ImageProcessingInstructions::fromCropScaleValues(1920, 1080, 100, 80, ['crop' => '']);
    echo "done\n";

    2) Execute it via ddev exec php crop-test.php

    Warning: Undefined array key 1 in .../ImageProcessingInstructions.php on line 338
    Warning: Undefined array key 2 in .../ImageProcessingInstructions.php on line 338
    Warning: Undefined array key 3 in .../ImageProcessingInstructions.php on line 338

    You’re right that an empty crop should be guarded away — and that’s exactly the inconsistency: streamlineOptions() does not remove it, while its sibling does.

    • streamlineOptions() enters via isset($options['crop']) (true for ‘’); json_decode('') is falsy, so it reaches explode(',', '', 4) (line 338) → the warnings → and builds new Area(0, 0, 0, 0) . The following if (… && $options['crop']->isEmpty()) unset(…) does not drop it, because Area::isEmpty() only matches the full-image area (x=0, y=0, width=1, height=1), not (0,0,0,0).
    • getConfigurationForImageCropScaleMask() (same explode pattern) already guards it with a truthy check if ($configuration['crop'] ?? null) , which correctly skips ‘’.

    The surviving zero-area also causes a fatal DivisionByZeroError further down — line 174 (width, no height) or line 227 (the call above without the upscaling flag).

    Re “custom code should guard too”: agreed in principle, but an empty crop is a normal stored value — sys_file_reference.crop is empty for any reference created outside the backend crop field (e.g. an Extbase FileReference persisted by an importer has no crop property at all). Aligning streamlineOptions() with its sibling (treat empty crop as “no crop”) would fix it centrally.

    Thanks!

  3. Gerrit Code Review pushed patch set 1 for main to change 94530 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2026-06-18T18:00:58+00:00" > 06/18/26, 18:00 </span>

  4. Garvin Hicking commented <span data-processor="relativetime" data-value="2026-06-18T18:05:52+00:00" > 06/18/26, 18:05 </span>

    Thank you for the further write up, that helped me chew through it a bit more. I agree this needs fixing. I tried a minimal approach in the attached patch, could you check it out and tell me what you think of it? Thanks!

  5. Andreas Stephan commented <span data-processor="relativetime" data-value="2026-06-19T07:16:33+00:00" > 06/19/26, 07:16 </span>

    Looking good – works as expected. Thanks!

    Could this fix also be backported to 13.4? The Releases: line currently lists only main and 14.3, but the bug is still present in 13.4 (verified locally on 13.4.32, the latest release).

  6. Garvin Hicking commented <span data-processor="relativetime" data-value="2026-06-19T09:14:40+00:00" > 06/19/26, 09:14 </span>

    Thhanks for that feedback. 13.4 is in “high prio bugfix” mode and I’m not sure yet I can rectify this to be seen as such – especially if you use this API in a way that you can actually control to “remove” an empty crop string.

    So I’m leaning towards “no backport to 13.4” but of course this is a discussion where other mergers can chime in too! Please bring that up in the patch on gerrit ideally!

  7. Garvin Hicking commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-06-22T14:25:12+00:00" > 06/22/26, 14:25 </span>

    Applied in changeset commit:a339838597b8ff8b25453109e7217690b2f60936.

  8. Andreas Stephan commented <span data-processor="relativetime" data-value="2026-06-25T07:44:57+00:00" > 06/25/26, 07:44 </span>

    Thanks! Unfortunately we don’t use this API in a way we’re able to remove the empty crop string. My example was a highly contrived scenario, so that you could understand the problem more easily.

    In our case the empty crop is not caller-controlled — it’s produced by fluid_styled_content itself.

    The “click-enlarge” rendering ( ClickEnlargeViewHelper → ContentObjectRenderer::imageLinkWrap() ) uses lib.contentElement.settings.media.popup , which contains:

    crop.data = file:current:crop

    For a file reference whose crop is empty — the normal state for any reference created without the FormEngine image-manipulation field (programmatic/Extbase FileReference, importers, or FAL image fields configured without cropVariants) — file:current:crop resolves to ‘’. Core then hands that straight on:

    imageLinkWrap() → $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, ['crop' => '', ...]) → ImageProcessingInstructions::fromCropScaleValues() → streamlineOptions() → the Undefined array key warnings (and a DivisionByZeroError in the width-only branch).

    So the whole chain is core-internal ( fluid_styled_content + cms-core ), triggered by an ordinary uncropped image that has “click-enlarge” enabled. In our case it only surfaced more visibly because the content is rendered uncached ( USER_INT ) via RecordsContentObject — but that integration never calls the image-processing API or sets the crop, so there’s no point at which it could “remove” the empty crop. Any site using fluid_styled_content click-enlarge on an uncropped image hits the same path.

    Therefore it would be great if this fix could be backported to 13.4

  9. Gerrit Code Review pushed patch set 1 for 13.4 to change 94583 status Resolved Under Review <span data-processor="relativetime" data-value="2026-06-25T09:52:52+00:00" > 06/25/26, 09:52 </span>

  10. Garvin Hicking commented and changed status Under Review Closed <span data-processor="relativetime" data-value="2026-06-26T11:50:26+00:00" > 06/26/26, 11:50 </span>

    Hi!

    We’ve decided this can be backported to 13.4, the patch was merged and will be part of the next release :)

    Thanks for being constructive on moving this forward!