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

DataURI can lose information in some charset environments

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx22
    • jfx20
    • javafx
    • None
    • b16

      DataURI uses the following implementation to decode the percent-encoded payload of a "data" URI:

      ```
      ...
      String data = uri.substring(dataSeparator + 1);
      Charset charset = Charset.defaultCharset();
      ...
      URLDecoder.decode(data.replace("+", "%2B"), charset).getBytes(charset)
      ```

      This approach only works if the charset that is passed into `URLDecoder.decode` and `String.getBytes` doesn't lose information when converting between `String` and `byte[]` representations, as might happen in a US-ASCII environment.

      The bug should be fixed by not using `URLDecoder`, but instead simply decoding percent-encoded escape sequences as specified by RFC 3986, page 11.

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: