core icon indicating copy to clipboard operation
core copied to clipboard

Perform QA for Improvements to the ImageAPI in version 5.1.6

Open patrick-schweiger opened this issue 5 months ago β€’ 3 comments

Description

A backport of some improvements/fixes in the ImageAPI which is impacting a customer in version 5.1.6 and leading to outages.Β These fixes might help with their ongoing outages.Β The improvements are untested and should be run and tested somewhere to make sure the image stuff still works. https://github.com/dotCMS/core/pull/36210

Acceptance Criteria

  • Successfully pass QA and ensure image functionality is not broken

Priority

Medium

Additional Context

This should be completed as part of the maintenance team sprint beginning on Monday, June 22. Estimate at 3 or 5 pointer.

patrick-schweiger avatar Jun 18 '26 13:06 patrick-schweiger

This one needs to be merged first https://github.com/dotCMS/core/pull/36210 @dsolistorres @gortiz-dotcms

dsilvam avatar Jun 29 '26 18:06 dsilvam

πŸ”΄ QA Failed β€” image processing is broken out-of-the-box

Verified PR #36210 (backport-image-improvements-5.1.6 @ f2ca3c6a) on a native-arm64 build of the branch + ES 6.1.3_for_5.1.6 + Postgres 13, demo starter. With the default configuration, every server-side image transformation fails.

Symptom

Any request through the image filter exporter returns HTTP 404, while raw file delivery still works:

GET /contentAsset/image/<id>/fileAsset/filter/Resize/resize_w/300   -> 404
GET /contentAsset/raw-data/<id>/fileAsset                            -> 200 (unaffected)

Backend log on every image request:

WARN  filter.ImageFilter: provider == null!
ERROR servlets.BinaryExporterServlet: [BinaryContentExporterException] An error occurred when accessing
'/image/<id>/fileAsset/filter/Resize/resize_w/300': provider == null!

This affects all filters (resize, thumbnail, crop, jpeg, png, gif, pdf) because the exporter resolves the engine on every request.

Root cause

ImageFilterApiImpl.deregisterProviders() deregisters a hard-coded WebP reader SPI but never null-checks the lookup result:

// ImageFilterApiImpl.java
private String[] providersToIgnore = Config.getStringArrayProperty(
    "IMAGE_READER_SPIS_TO_DEREGISTER",
    new String[]{"net.sf.javavp8decoder.imageio.WebPImageReaderSpi"});   // <-- not present in 5.1.6's deps
...
ImageReaderSpi provider = lookupProviderByName(registry, providerClazz); // returns null (ClassNotFoundException)
registry.deregisterServiceProvider(provider);                            // deregister(null) throws IllegalArgumentException

The backport bumps TwelveMonkeys to 3.7.0 and bundles imageio-webp-3.7.0.jar, whose WebP SPI is com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi. The deregister default still names the old net.sf.javavp8decoder... class, which is absent from the 5.1.6 classpath β†’ Class.forName fails β†’ lookupProviderByName returns null β†’ deregisterServiceProvider(null) throws. The exporter calls imageFilterAPI().resolveFilters(...) β†’ ImageEngine.resolve() β†’ the ImageFilterApiImpl constructor on every request, so the failure is total.

This is an incomplete backport: the deregistration code came from newer dotCMS where net.sf.javavp8decoder was the actual WebP dependency. 5.1.6 uses TwelveMonkeys instead, so the target class doesn't exist.

Confirmed fix

Pointing the config at the actually-registered class makes every filter work again:

Config …/filter/Resize/resize_w/300
Default (ships broken) ❌ HTTP 404, provider == null!
IMAGE_READER_SPIS_TO_DEREGISTER=com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi βœ… HTTP 200, PNG 300Γ—243

With the corrected config, the full pipeline passes β€” Resize, Thumbnail (150Γ—100), Crop (200Γ—150), Resize+Jpeg chain, GIF resize, default Png, and the PDF render path (#23384) handled a 3-page / 2500Β² PDF under a 512 MB heap with no OOM.

Recommended fix (code): add a null guard in deregisterProviders() β€” this is a latent NPE on any branch where the named SPI isn't registered:

ImageReaderSpi provider = lookupProviderByName(registry, providerClazz);
if (provider != null) {
    registry.deregisterServiceProvider(provider);
}

Optionally also correct the default class name for 5.1.6's dependency set. Operators can mitigate immediately without a rebuild by setting IMAGE_READER_SPIS_TO_DEREGISTER (env DOT_IMAGE_READER_SPIS_TO_DEREGISTER) to the TwelveMonkeys class above, or to empty.

dsolistorres avatar Jun 30 '26 15:06 dsolistorres

βœ… QA Passed β€” fix applied and verified

The image-processing regression reported above has been fixed and the full filter pipeline re-verified end-to-end on a native build of the branch (ES 6.1.3_for_5.1.6 + Postgres 13, demo starter).

Fix

Commit 117b7f5e34 on backport-image-improvements-5.1.6 (PR #36210) β€” a null guard in ImageFilterApiImpl.deregisterProviders():

ImageReaderSpi provider = lookupProviderByName(registry, providerClazz);
if (provider != null) {
    registry.deregisterServiceProvider(provider);
}

Why the guard is needed here but not in evergreen

deregisterProviders() removes the net.sf.javavp8decoder.imageio.WebPImageReaderSpi WebP reader so ImageIO doesn't pick that (inferior) decoder. The code is identical on main and has no null check there either β€” the difference is the dependency set, not the code:

  • evergreen (main): the net.sf.javavp8decoder library is on the classpath (main's own code references net.sf.javavp8decoder.imageio.WebPImageReader directly), so the default SPI class exists and is registered β†’ lookupProviderByName returns a real provider β†’ deregisterServiceProvider(provider) succeeds. The null path never happens. (main also has the preferred native libvips engine; the JVM engine is the fallback.)
  • 5.1.6.k backport: javavp8decoder was not backported. Instead the backport adds TwelveMonkeys imageio-webp 3.7.0, whose WebP reader is a different class (com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi). So the hard-coded net.sf.javavp8decoder... SPI is absent β†’ lookupProviderByName returns null β†’ deregisterServiceProvider(null) throws IllegalArgumentException, which broke every image request through ImageFilterExporter (HTTP 404, provider == null!).

On 5.1.6.k there is simply no javavp8decoder reader to deregister (and none needs deregistering β€” TwelveMonkeys supplies WebP). The null guard makes deregisterProviders() tolerate "the SPI I was told to remove isn't here." (Strictly, the missing guard is a latent bug on main too; it just never fires because main's classpath matches the hard-coded default.)

Verification β€” every filter changed by the backport

Fixed build, default config, no config workaround. All returned HTTP 200 with correct output; zero provider == null / OOM:

Filter Test Result
Resize resize_w/300 300Γ—243 PNG βœ…
Scale (β†’Resize) scale_w/300 300Γ—243 PNG βœ…
Crop crop_w/200/crop_h/150 200Γ—150 PNG βœ…
Thumbnail thumbnail_w/150/thumbnail_h/100 150Γ—100 PNG βœ…
Jpeg jpeg_q/70 JPEG βœ…
Png Png 2000Γ—1299 PNG βœ…
Gif Gif GIF89a βœ…
Grayscale Grayscale PNG βœ…
Exposure exposure_exp/1.2 PNG βœ…
Gamma gamma_g/1.5 PNG βœ…
Hsb hsb_h/0.5/hsb_s/1.0/hsb_b/1.0 PNG βœ…
Flip flip_flip/true PNG βœ…
Rotate rotate_a/90 1100Γ—1355 (dims swapped) βœ…
Resize,Jpeg (chain) resize_w/400/jpeg_q/70 JPEG βœ…
Resize on GIF (new ResizeGifImageFilter) resize_w/64 64Γ—224 βœ…
PDF (#23384 OOM fix) filter/PDF 612Γ—792 PNG βœ…
PDF,Resize (chain) PDF,Resize/resize_w/200 200Γ—258 PNG βœ…
PDF page/dpi pdf_page/2/pdf_dpi/150 1275Γ—1649 PNG βœ…

Notes: SubSampleImageFilter (new) is exercised internally by ResizeImageFilter on large downscales. PDFImageFilter (#23384) was also load-tested in isolation β€” a 3-page / 2500Β² PDF rendered under a capped 512 MB heap with no OOM.

Verdict: PASS. Recommend merging PR #36210 with commit 117b7f5e34 included.

dsolistorres avatar Jul 01 '26 21:07 dsolistorres