Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-22475

Prevent files from getting empty values for the "Mime Type" information

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • None
    • None
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

    Description

      NOTE: This suggestion is for JIRA Server. Using JIRA Cloud? See the corresponding suggestion.

      Symptom

      Attempting to view an attachment throws the following exception:

      2012-11-20 14:26:32,775 http-8080-18 ERROR captain.planet 866x819921x1 9fma0l 127.0.0.1 /secure/attachment/23918/secret_plans.pdf [jira.web.servlet.ViewAttachmentServlet] Error serving file for path /23918/secret_plans.pdf: null
      java.lang.NullPointerException
      	at java.util.regex.Matcher.getTextLength(Unknown Source)
      	at java.util.regex.Matcher.reset(Unknown Source)
      	at java.util.regex.Matcher.<init>(Unknown Source)
      	at java.util.regex.Pattern.matcher(Unknown Source)
      	at com.atlassian.gzipfilter.selector.PatternMatcher.matches(PatternMatcher.java:39)
      	at com.atlassian.gzipfilter.selector.UrlRewriteGzipCompatibilitySelector.shouldGzip(UrlRewriteGzipCompatibilitySelector.java:31)
      	at com.atlassian.gzipfilter.SelectingResponseWrapper.setContentType(SelectingResponseWrapper.java:55)
      	at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130)
      	at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130)
      	at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130)
      

      Cause

      Somehow it is possible that an uploaded file attachment will end up having an empty string as the mime type in the database (FILEATTACHMENT.MIMETYPE). Please see the picture:

      Unfortunately, there are no steps to reproduce the problem. The suspect is that the problem happens when JIRA is under heavy load or concurrent modification of the same issue.

      As a safeguard to avoid it happening again in the future, it can be made the following modification in JIRA's code, more specifically in the com.atlassian.jira.util.mime.MimeManager.java file:

      com.atlassian.jira.util.mime.MimeManager.java
      public String getSanitisedMimeType(String existingMimeType, String fileName)
      {
          //only override the mime-type if it is a generic type
          /**
           * @SKYPE Also override mime-type when the browser does not send any mime-type for some reason as 
           *        this can cause not downloadable file attachments. 
           * @DEV Priit Parmann
           */
          if (existingMimeType == null || existingMimeType.equals("") || GENERIC_MIME_TYPES.contains(existingMimeType))
          {
              return getSuggestedMimeType(fileName);
          }
          else
          {
              return existingMimeType;
          }
      }
      

      It would be great if Atlassian would consider adding the same (or better) modification to the next release so that in the future there would be no attachments without mime types.

      The case of empty mime type should also be handled when downloading the file.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              lrheinheimer Leticia Rafaela Rheinheimer [Atlassian]
              Votes:
              6 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: