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

URLConnection.guessContentTypeFromStream returns image/jpg for some JPEG images

    Details

    • Subcomponent:
    • Resolved In Build:
      b100
    • CPU:
      x86_64
    • OS:
      windows_7

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_60"
        Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
        Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        For some JPEG images the method java.net.URLConnection#guessContentTypeFromStream will return the MIME type image/jpg, which is not a valid, registered IANA mime type for JPEG images.

        For other images, the correct MIME type (image/jpeg) is returned.

        It could be open for debate how invalid image/jpg truly is, but here's the IANA list:
        http://www.iana.org/assignments/media-types/media-types.xhtml

        Regardless of the validity of the MIME type, I could not find any information on *why* Java will return two different MIME types for JPEGs.

        Sadly I cannot provide the image that triggered the relevant detection code (it's from a customer), but after some googling, it seems like the relevant JPEG APP14 header is an application specific header, in this case from Adobe (see http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html).


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The function should return image/jpeg for all JPEG images, not just some.
        ACTUAL -
        The function returned image/jpg for some JPEG images encoded with Adobe software.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        Manually replacing image/jpg in the result with image/jpeg.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rpatil Ramanand Patil
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  9 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: