On Mon, 22 Nov 2021 17:52:06 GMT, Michael Strauß <mstra...@openjdk.org> wrote:

> `com.sun.javafx.iio.ImageStorage` currently ignores the MIME image subtype 
> specified for images encoded in data URIs. This should be improved as follows:
> 
> 1. If the specified image subtype is not supported, an exception will be 
> thrown.
> 2. If the specified image subtype is supported, but the data contained in the 
> URI is of a different (but also supported) image format, the image will be 
> loaded and a warning will be logged. For example, if the MIME type is 
> "image/jpeg", but the image data is PNG, the following warning will be 
> generated:
> 
> 
> Image format 'PNG' does not match MIME type 'image/jpeg' in URI 
> 'data:image/jpeg;base64,iVBORw0KGgoAAA...AAAElFTkSuQmCC'
> 
> 
> Also, the javadoc of `javafx.scene.image.Image` incorrectly states:
> 
>     94    * If a URL uses the "data" scheme, the data must be base64-encoded
>     95    * and the MIME type must either be empty or a subtype of the
>     96    * {@code image} type.
> 
> However, omitting the MIME type of a data URI is specified to imply 
> "text/plain" (RFC 2397, section 2). Since the `com.sun.javafx.util.DataURI` 
> class is implemented according to this specification, trying to load an image 
> without MIME type correctly fails with an `ImageStorageException`: 
> "Unexpected MIME type: text".
> 
> The solution is to fix the documentation:
> 
>       94    * If a URL uses the "data" scheme, the data must be base64-encoded
>     - 95    * and the MIME type must either be empty or a subtype of the
>     - 96    * {@code image} type.
>     + 95    * and the MIME type must be a subtype of the {@code image} type.
>     + 96    * The MIME type must match the image format of the data contained 
> in
>     + 97    * the URL. In case of a mismatch between MIME type and image 
> format,
>     + 98    * the image will be loaded if the image format can be determined 
> by
>     + 99    * JavaFX, and a warning will be logged.

This pull request has now been integrated.

Changeset: f326e78f
Author:    Michael Strauß <mstra...@openjdk.org>
Committer: Kevin Rushforth <k...@openjdk.org>
URL:       
https://git.openjdk.java.net/jfx/commit/f326e78ffdfcbbc9085bc50a38e0b4454b757157
Stats:     266 lines in 16 files changed: 170 ins; 8 del; 88 mod

8277572: ImageStorage should correctly handle MIME types for images encoded in 
data URIs

Reviewed-by: kcr, arapte

-------------

PR: https://git.openjdk.java.net/jfx/pull/676

Reply via email to