Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-31079

Make MimetypeRegistryService#getMimetypeFromFile more robust

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 10.10
    • Fix Version/s: 10.10-HF65, 2021.x
    • Component/s: Core

      Description

      In some weird circumstances, a NPE could be thrown by MimetypeRegistryService#getMimetypeFromFile when trying to guess the MIME type from the file thanks to magic.xml

      java.lang.NullPointerException: null
      	at org.nuxeo.ecm.platform.mimetype.service.MimetypeRegistryService.getMimetypeFromFile(MimetypeRegistryService.java:232) ~[nuxeo-core-mimetype-10.10-HF53.jar:?]
      	at org.nuxeo.ecm.platform.thumbnail.factories.ThumbnailDocumentFactory.getDefaultThumbnail(ThumbnailDocumentFactory.java:120) ~[nuxeo-thumbnail-10.10-HF56.jar:?]
      	at org.nuxeo.ecm.platform.thumbnail.factories.ThumbnailDocumentFactory.getThumbnail(ThumbnailDocumentFactory.java:69) ~[nuxeo-thumbnail-10.10-HF56.jar:?]
      	at org.nuxeo.ecm.core.api.thumbnail.ThumbnailServiceImpl.getThumbnail(ThumbnailServiceImpl.java:93) ~[nuxeo-core-api-10.10-HF57.jar:?]
      	at org.nuxeo.ecm.platform.thumbnail.rendition.ThumbnailRenditionProvider.render(ThumbnailRenditionProvider.java:45) ~[nuxeo-thumbnail-10.10-HF56.jar:?]
      	at org.nuxeo.ecm.platform.rendition.impl.LiveRendition.computeRenditionBlobs(LiveRendition.java:62) ~[nuxeo-platform-rendition-api-10.10-HF08.jar:?]
      	at org.nuxeo.ecm.platform.rendition.impl.LazyRendition.getBlobs(LazyRendition.java:60) ~[nuxeo-platform-rendition-api-10.10-HF08.jar:?]
      	at org.nuxeo.ecm.platform.rendition.impl.LazyRendition.getBlob(LazyRendition.java:50) ~[nuxeo-platform-rendition-api-10.10-HF08.jar:?]
      	at org.nuxeo.ecm.restapi.server.jaxrs.rendition.RenditionObject.getRenditionBlob(RenditionObject.java:74) ~[nuxeo-rest-api-server-10.10-HF58.jar:?]
      	at org.nuxeo.ecm.restapi.server.jaxrs.rendition.RenditionObject.doGet(RenditionObject.java:79) ~[nuxeo-rest-api-server-10.10-HF58.jar:?] 

      => it happens to a customer with the file img/folder.gif (which exists on the server, otherwise we won't reach this point).

       

      I think 2 things should be changed:

      • at least, avoid the NPE by testing if m is null in this part of the code
                  MagicMatch match = Magic.getMagicMatch(file, true, false);
                  String mimeType;          
      
                      Collection<MagicMatch> possibilities = match.getSubMatches();
                      Iterator<MagicMatch> iter = possibilities.iterator();
                      MagicMatch m = iter.next();
                      mimeType = m.getMimeType(); 
      • maybe review the code to get the MIME type from the file name first, and then try to guess the MIME type from magic.xml if the file extension is unknown in Nuxeo registry.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: