Unexpected EOFException in ImageReaderSpi.canDecodeInput
Volodin, Vladislav
vladislav.volodin at sap.com
Wed May 18 08:04:41 UTC 2022
Hello Philip,
I have never used this object, but according to JavaDocs it says that IOException is thrown "if an I/O error occurs while reading the stream". So in theory, if we can read the file, but its size is less than we expect (e.g. a magic number length), why cannot we simply return "false" instead of throwing an exception? We can read the file, but it is small...
Isn't it a purpose of all "canXXXX" methods to return Boolean when expecting something, and throwing an exception under unpredictable circumstances? For example, File.canRead / File.canWrite don't throw an exception. Probably this is a bad example, and there maybe other examples that demonstrate a different result.
Kind regards,
Vlad
-----Original Message-----
From: client-libs-dev <client-libs-dev-retn at openjdk.java.net> On Behalf Of Philip Race
Sent: Dienstag, 17. Mai 2022 20:36
To: Martin Desruisseaux <martin.desruisseaux at geomatys.com>; client-libs-dev at openjdk.java.net
Subject: Re: Unexpected EOFException in ImageReaderSpi.canDecodeInput
Why is it unexpected ?
The method declares that it throws IOException .. which if thrown
clearly means the stream can't be de-coded.
Perhaps your point is that this then prevents control reaching the
reset, so that the next plugin
doesn't get its turn to also reject the truncated file.
I suppose I can see that might be a reasonable thing to do in the event
there's some image format
that has a large read requirement for the header validation and that the
following plugin may
see that there's a small valid image ?
But this fix is still putting it on each plugin to behave itself .. and
we already handle that in the ImageIO class
although I think it isn't perfect, as it still relies on co-operation
with regard to mark()
And if you call this directly, you can handle that just as well yourself
.. and still can't trust extra
plugins to behave ..,. so what is the use case for this fix ?
-phil.
On 5/17/22 5:48 AM, Martin Desruisseaux wrote:
> Hello
>
> I prepared a pull request at [1] for fixing an unexpected EOFException
> thrown by ImageReaderSpi.canDecodeInput(Object) in JDK implementations
> for BMP, WBMP, GIF, PNG and TIFF formats (JPEG is not impacted). This
> exception occurs when the stream has less than 8 bytes. For example,
> it occurs when probing all files in a directory if that directory
> contains empty files.
>
> If believe that in order to process, a bug report must be filled on
> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugs.openjdk.java.net%2F&data=05%7C01%7Cvladislav.volodin%40sap.com%7Ca6be9a838e654ba01c1b08da38342f9f%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C637884094036465515%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=s1VG8nCH9pJKY65IwOYcvKK%2Bk0QnLmLRol%2BJIdPOfTs%3D&reserved=0 ? Can someone hint me about how to do
> that (since I can not create a report myself)?
>
> Regards,
>
> Martin
>
> [1]https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fopenjdk%2Fjdk%2Fpull%2F8700&data=05%7C01%7Cvladislav.volodin%40sap.com%7Ca6be9a838e654ba01c1b08da38342f9f%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C637884094036465515%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=r%2BR8qM4b8BHMiFSN2vF2nEsLSZAbUFagi5BY3pLnJzE%3D&reserved=0
More information about the client-libs-dev
mailing list