Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8277653

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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx18, jfx19
    • javafx
    • None
    • behavioral
    • low
    • Java API
    • JDK

      Summary

      ImageStorage should inspect the MIME image subtype of images encoded in data URIs, and log a warning if it doesn't match the actual image format.

      Problem

      Currently, ImageStorage ignores the MIME image subtype of images encoded in data URIs.

      Solution

      The behavior of ImageStorage will be changed 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'

      Specification

      The documentation of javafx.scene.image.Image will be changed:

      92    * <p>The RFC 2397 "data" scheme for URLs is supported in addition to
      93    * the protocol handlers that are registered for the application.
      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.

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: