Skip to main content

[JAI] Bad magic number decoding TIFF

3 replies [Last post]
Anonymous

I had an application working reading TIFF images from an email inbox using
JAI 1.1.2_01 and Java Mail 1.3.2. Now, when trying with the newer Java Mail
1.3.3, the JAI method of reading now fails on all images. It seems JAI does
not like decoding the InputStream to the TIFF image that Java Mail is giving
now. The resulting exception says, "Bad magic number, should be 42."

I tested dumping the InputStream's bytes to disk and I do have a valid TIFF
there. All I can think is something must be different with the InputStream
that JAI cannot decode. Any suggestions?

Where it breaks:

PlanarImage pi = JAI.create("tiff", pb);
TIFFDirectory dir = (TIFFDirectory) pi.getProperty("tiff_directory");

Stack Trace:

javax.media.jai.util.ImagingException: All factories fail for the operation
"tiff"
at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperatio
nRegistry.java:481)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
at
javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
at
javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
)
at
javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
at
javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
)
at
javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.jav
a:135)
at
javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySou
rceImpl.java:306)
at
javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
at javax.media.jai.RenderedOp.getProperty(RenderedOp.java:1979)
at net.nighthawk.faxviewer.util.TIFF60.readAndFormat(TIFF60.java:84)
at
net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
aFAXMessageParser.java:140)
at
net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
aFAXMessageParser.java:28)
at
net.nighthawk.faxviewer.server.mail.EmailReceiver.run(EmailReceiver.java:143
)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
... 16 more
Caused by: java.lang.IllegalArgumentException: Bad magic number, should be
42.
at
com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:5
94)
at
com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.ja
va:105)
at
com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImage
Decoder.java:109)
at
com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)

Thank you,

-Aaron Bruegl

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

Aaron,

Would you be able to send the byte dump that the reader sees? Please post
directly to me.

Brian

On Mon, 17 Oct 2005, Aaron Bruegl wrote:

> I had an application working reading TIFF images from an email inbox using
> JAI 1.1.2_01 and Java Mail 1.3.2. Now, when trying with the newer Java Mail
> 1.3.3, the JAI method of reading now fails on all images. It seems JAI does
> not like decoding the InputStream to the TIFF image that Java Mail is giving
> now. The resulting exception says, "Bad magic number, should be 42."
>
> I tested dumping the InputStream's bytes to disk and I do have a valid TIFF
> there. All I can think is something must be different with the InputStream
> that JAI cannot decode. Any suggestions?
>
>
>
> Where it breaks:
>
> PlanarImage pi = JAI.create("tiff", pb);
> TIFFDirectory dir = (TIFFDirectory) pi.getProperty("tiff_directory");
>
> Stack Trace:
>
> javax.media.jai.util.ImagingException: All factories fail for the operation
> "tiff"
> at
> javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
> at
> javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperatio
> nRegistry.java:481)
> at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
> at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
> at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
> at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
> at
> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
> at
> javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
> )
> at
> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
> at
> javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
> )
> at
> javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.jav
> a:135)
> at
> javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySou
> rceImpl.java:306)
> at
> javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
> at javax.media.jai.RenderedOp.getProperty(RenderedOp.java:1979)
> at net.nighthawk.faxviewer.util.TIFF60.readAndFormat(TIFF60.java:84)
> at
> net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
> aFAXMessageParser.java:140)
> at
> net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
> aFAXMessageParser.java:28)
> at
> net.nighthawk.faxviewer.server.mail.EmailReceiver.run(EmailReceiver.java:143
> )
> at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> )
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
> at
> javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
> ... 16 more
> Caused by: java.lang.IllegalArgumentException: Bad magic number, should be
> 42.
> at
> com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:5
> 94)
> at
> com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.ja
> va:105)
> at
> com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImage
> Decoder.java:109)
> at
> com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
> at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
>
>
> Thank you,
>
> -Aaron Bruegl
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Multimedia, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Aaron Bruegl

If anyone is interested in what was causeing this problem, it was the
following bug in Java Mail

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6332559

This gave a bad stream to JAI, which caused the decoding to fail giving a
strange exception message. I switched to using ImageIO for JAI to read the
stream, and this gave a better exception message of
"javax.imageio.IIOException: Couldn't seek!".

Then I was able to find the bug in Java Mail, and was told it will be fixed
in its next release (after 1.3.3_01).

-Aaron

-----Original Message-----
From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
Sent: Monday, October 17, 2005 5:35 PM
To: interest@jai.dev.java.net
Subject: Re: [JAI] Bad magic number decoding TIFF

Aaron,

Would you be able to send the byte dump that the reader sees? Please post
directly to me.

Brian

On Mon, 17 Oct 2005, Aaron Bruegl wrote:

> I had an application working reading TIFF images from an email inbox using
> JAI 1.1.2_01 and Java Mail 1.3.2. Now, when trying with the newer Java
Mail
> 1.3.3, the JAI method of reading now fails on all images. It seems JAI
does
> not like decoding the InputStream to the TIFF image that Java Mail is
giving
> now. The resulting exception says, "Bad magic number, should be 42."
>
> I tested dumping the InputStream's bytes to disk and I do have a valid
TIFF
> there. All I can think is something must be different with the InputStream
> that JAI cannot decode. Any suggestions?
>
>
>
> Where it breaks:
>
> PlanarImage pi = JAI.create("tiff", pb);
> TIFFDirectory dir = (TIFFDirectory) pi.getProperty("tiff_directory");
>
> Stack Trace:
>
> javax.media.jai.util.ImagingException: All factories fail for the
operation
> "tiff"
> at
>
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
> at
>
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperatio
> nRegistry.java:481)
> at
javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
> at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
> at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
> at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
> at
> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
> at
>
javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
> )
> at
> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
> at
>
javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
> )
> at
>
javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.jav
> a:135)
> at
>
javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySou
> rceImpl.java:306)
> at
> javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
> at javax.media.jai.RenderedOp.getProperty(RenderedOp.java:1979)
> at
net.nighthawk.faxviewer.util.TIFF60.readAndFormat(TIFF60.java:84)
> at
>
net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
> aFAXMessageParser.java:140)
> at
>
net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
> aFAXMessageParser.java:28)
> at
>
net.nighthawk.faxviewer.server.mail.EmailReceiver.run(EmailReceiver.java:143
> )
> at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> )
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
> at
>
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
> ... 16 more
> Caused by: java.lang.IllegalArgumentException: Bad magic number, should be
> 42.
> at
>
com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:5
> 94)
> at
>
com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.ja
> va:105)
> at
>
com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImage
> Decoder.java:109)
> at
> com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
> at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
>
>
> Thank you,
>
> -Aaron Bruegl
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Multimedia, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

On Wed, 19 Oct 2005, Aaron Bruegl wrote:

> If anyone is interested in what was causeing this problem, it was the
> following bug in Java Mail
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6332559

Thanks for posting this message to close the loop.

> This gave a bad stream to JAI, which caused the decoding to fail giving a
> strange exception message. I switched to using ImageIO for JAI to read the
> stream, and this gave a better exception message of
> "javax.imageio.IIOException: Couldn't seek!".

As you will recall, the last exception in the chain was in fact

Caused by: java.io.EOFException
at
javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.jav
a:211)

that is to say an EOFException. The TIFF image reader just uses the message
"Can't Seek" because the IO method within the try-catch block is seek(). The
ultimate cause was the EOF.

Brian

> Then I was able to find the bug in Java Mail, and was told it will be fixed
> in its next release (after 1.3.3_01).
>
> -Aaron
>
>
>
> -----Original Message-----
> From: Brian.Burkhalter@Sun.COM [mailto:Brian.Burkhalter@Sun.COM]
> Sent: Monday, October 17, 2005 5:35 PM
> To: interest@jai.dev.java.net
> Subject: Re: [JAI] Bad magic number decoding TIFF
>
> Aaron,
>
> Would you be able to send the byte dump that the reader sees? Please post
> directly to me.
>
> Brian
>
> On Mon, 17 Oct 2005, Aaron Bruegl wrote:
>
>> I had an application working reading TIFF images from an email inbox using
>> JAI 1.1.2_01 and Java Mail 1.3.2. Now, when trying with the newer Java
> Mail
>> 1.3.3, the JAI method of reading now fails on all images. It seems JAI
> does
>> not like decoding the InputStream to the TIFF image that Java Mail is
> giving
>> now. The resulting exception says, "Bad magic number, should be 42."
>>
>> I tested dumping the InputStream's bytes to disk and I do have a valid
> TIFF
>> there. All I can think is something must be different with the InputStream
>> that JAI cannot decode. Any suggestions?
>>
>>
>>
>> Where it breaks:
>>
>> PlanarImage pi = JAI.create("tiff", pb);
>> TIFFDirectory dir = (TIFFDirectory) pi.getProperty("tiff_directory");
>>
>> Stack Trace:
>>
>> javax.media.jai.util.ImagingException: All factories fail for the
> operation
>> "tiff"
>> at
>>
> javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
>> at
>>
> javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperatio
>> nRegistry.java:481)
>> at
> javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
>> at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
>> at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
>> at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
>> at
>> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
>> at
>>
> javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
>> )
>> at
>> javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
>> at
>>
> javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280
>> )
>> at
>>
> javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.jav
>> a:135)
>> at
>>
> javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySou
>> rceImpl.java:306)
>> at
>> javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
>> at javax.media.jai.RenderedOp.getProperty(RenderedOp.java:1979)
>> at
> net.nighthawk.faxviewer.util.TIFF60.readAndFormat(TIFF60.java:84)
>> at
>>
> net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
>> aFAXMessageParser.java:140)
>> at
>>
> net.nighthawk.faxviewer.server.mail.HylaFAXMessageParser.parseAttachment(Hyl
>> aFAXMessageParser.java:28)
>> at
>>
> net.nighthawk.faxviewer.server.mail.EmailReceiver.run(EmailReceiver.java:143
>> )
>> at java.lang.Thread.run(Thread.java:595)
>> Caused by: java.lang.reflect.InvocationTargetException
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at
>>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
>> )
>> at
>>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
>> .java:25)
>> at java.lang.reflect.Method.invoke(Method.java:585)
>> at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
>> at
>>
> javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
>> ... 16 more
>> Caused by: java.lang.IllegalArgumentException: Bad magic number, should be
>> 42.
>> at
>>
> com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:5
>> 94)
>> at
>>
> com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.ja
>> va:105)
>> at
>>
> com.sun.media.jai.codecimpl.TIFFImageDecoder.decodeAsRenderedImage(TIFFImage
>> Decoder.java:109)
>> at
>> com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:96)
>> at com.sun.media.jai.opimage.TIFFRIF.create(TIFFRIF.java:53)
>>
>>
>> Thank you,
>>
>> -Aaron Bruegl
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
>> For additional commands, e-mail: interest-help@jai.dev.java.net
>>
>>
>
> ----------------
> Brian Burkhalter
> Java Multimedia, Imaging, and Graphics
> Sun Microsystems, Inc.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> This email message is for the sole use of the intended recipient(s)
> and may contain confidential and privileged information. Any
> unauthorized review, use, disclosure or distribution is prohibited.
> If you are not the intended recipient, please contact the sender by
> reply email and destroy all copies of the original message.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Multimedia, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net