cantaloupe
cantaloupe copied to clipboard
Internal server error when a TIFF image uses EXIF long values for rotation
Some TIFF images may use a long integer value instead of a short one to represent EXIF orientation metadata. Cantaloupe does not support that and raises an error (tested on develop, 5.0.3, and 5.0.5).
Here is the resulting stack trace
java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
at edu.illinois.library.cantaloupe.image.Metadata.readOrientationFromEXIF(Metadata.java:157)
at edu.illinois.library.cantaloupe.image.Metadata.lambda$getOrientation$0(Metadata.java:138)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at edu.illinois.library.cantaloupe.image.Metadata.getOrientation(Metadata.java:138)
at edu.illinois.library.cantaloupe.resource.iiif.v2.ImageInfoFactory.newImageInfo(ImageInfoFactory.java:85)
at edu.illinois.library.cantaloupe.resource.iiif.v2.InformationResource.newRepresentation(InformationResource.java:125)
at edu.illinois.library.cantaloupe.resource.iiif.v2.InformationResource.doGET(InformationResource.java:87)
at edu.illinois.library.cantaloupe.resource.HandlerServlet.handle(HandlerServlet.java:97)
at edu.illinois.library.cantaloupe.resource.HandlerServlet.doGet(HandlerServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:791)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:516)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:773)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:905)
at java.base/java.lang.Thread.run(Thread.java:829)
I was able to find the underlying issue by looking at the trace logs, especially for EXIF parsing:
ark-cantaloupe | 09:08:40.006 [qtp320304382-15] TRACE e.i.l.c.c.InfoService - Info for test.TIF: {"applicationVersion":"5.0.3","serializationVersion":4,"identifier":"test.TIF","mediaType":"image/tiff","numResolutions":1,"images":[{"width":2480,"height":3507,"tileWidth":2480,"tileHeight":3507}],"metadata":{"exif":{"fields":[{"tag":256,"dataType":4,"value":2480},{"tag":257,"dataType":4,"value":3507},{"tag":258,"dataType":3,"value":1},{"tag":259,"dataType":3,"value":4},{"tag":262,"dataType":3,"value":0},{"tag":274,"dataType":4,"value":1},{"tag":277,"dataType":3,"value":1},{"tag":278,"dataType":4,"value":3507},{"tag":282,"dataType":5,"value":[300,1]},{"tag":283,"dataType":5,"value":[300,1]},{"tag":296,"dataType":3,"value":2},{"tag":305,"dataType":2,"value":"Pixel Translations Inc., PIXTIFF Version 1.157"}]}}}
The orientation tag is n°274 and uses here the data type 4 which is LONG
.
But the readOrientationFromEXIF only supports short integers.
This is somewhat weird error as from the spec I found here and it shows that orientation tag is int16u
(which is a short
). Wondering whether parsing EXIF data might be bad?
I experienced the same. Plan for new release?
@janhoy already working on back-porting his changes to v5.0 branch. Though I'm not really sure is my approach is a good one.