ImageInfo() on certain files causes exceptions in the log, but not on the page

We’re getting a number of apache imaging exceptions written to our application.log files. This happens when user(s) upload a less-than-valid image file which ends up getting run through imageInfo().

<cfset foo = imageInfo(imageRead("./badImage.jpg"))/>

I tried attaching one of the bad images to this post, but it gets resized so I don’t know if it will still be bad. I have uploaded the raw image file here: 43459A.jpg - Google Drive

The page does not throw any exceptions; the user is not affected. But this exception does clutter up the log. Can something be done to silence this exception? I think the problem is happening in the Apache imaging library, from the Lucee image extension.

Might be line 60 of this file? I see in the catch it only does Debug.debug(e);, which might be what is causing these log entries, but not causing a Lucee exception.

FYI the result from ImageInfo() appears correct, even with the bad image.

Window: Windows
Java Version: 11.0.21
Tomcat Version: 9.0.83
Lucee Version: I’ve tried 5.3.12.1 and 5.4.4.38

I forgot to include the stack trace, here it is.

"ERROR","ajp-nio-127.0.0.1-8009-exec-2","12/21/2023","15:49:29","imaging","Could not read block (block start: 984, block length: -62, data length: 922).;java.io.IOException: Could not read block (block start: 984, block length: -62, data length: 922).
        at org.apache.commons.imaging.common.bytesource.ByteSourceArray.getBlock(ByteSourceArray.java:46)
        at org.apache.commons.imaging.formats.tiff.TiffReader.getJpegRawImageData(TiffReader.java:480)
        at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectory(TiffReader.java:215)
        at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectory(TiffReader.java:112)
        at org.apache.commons.imaging.formats.tiff.TiffReader.readDirectories(TiffReader.java:105)
        at org.apache.commons.imaging.formats.tiff.TiffReader.read(TiffReader.java:408)
        at org.apache.commons.imaging.formats.tiff.TiffReader.readContents(TiffReader.java:402)
        at org.apache.commons.imaging.formats.tiff.TiffImageParser.getMetadata(TiffImageParser.java:139)
        at org.apache.commons.imaging.formats.tiff.TiffImageParser.getMetadata(TiffImageParser.java:66)
        at org.apache.commons.imaging.ImageParser.getMetadata(ImageParser.java:222)
        at org.apache.commons.imaging.formats.jpeg.JpegImageParser.getExifMetadata(JpegImageParser.java:359)
        at org.apache.commons.imaging.formats.jpeg.JpegImageParser.getMetadata(JpegImageParser.java:319)
        at org.apache.commons.imaging.formats.jpeg.JpegImageParser.getMetadata(JpegImageParser.java:65)
        at org.apache.commons.imaging.Imaging.getMetadata(Imaging.java:653)
        at org.apache.commons.imaging.Imaging.getMetadata(Imaging.java:648)
        at org.lucee.extension.image.Metadata.addExifInfoToStruct(Metadata.java:65)
        at org.lucee.extension.image.Image.info(Image.java:402)
        at org.lucee.extension.image.functions.ImageInfo.call(ImageInfo.java:33)
        at org.lucee.extension.image.functions.ImageInfo.invoke(ImageInfo.java:38)
        at lucee.runtime.functions.FunctionHandlerPool.invoke(FunctionHandlerPool.java:40)
        at schedules.test_cfm$cf$5.call(/schedules/test.cfm:8)
        at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1056)
        at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:948)
        at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:219)
        at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44)
        at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2493)
        at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2478)
        at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2449)
        at lucee.runtime.engine.Request.exe(Request.java:45)
        at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1216)
        at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1162)
        at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
        at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)

Also some more details here: [IMAGING-177] java.io.IOException: Could not read block - ASF JIRA

I had similar issues once with errors, but the logs didn’t matter. An alternative to cfimage has always been imagemagick, a commandlne tool that had lot of powerful commands about image manipulation even before cfimage existed.

1 Like