Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-24098

File seems to be treated as Image when linking to it

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Medium Medium
    • Resolution: Fixed
    • Affects Version/s: 5.4.0, 5.4.1
    • Fix Version/s: Customer request
    • Component/s: DemoBundle
    • Labels:
      None
    • Environment:

      eZ Publish 5.4.0

      Description

      When linking to a file located under storage/original/application/ the following exception is thrown:

      CRITICAL - Uncaught PHP Exception eZ\Publish\Core\Base\Exceptions\InvalidArgumentException: "Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf" at /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php line 386
      


      Steps to reproduce:

      Start from an eZ Publish 5.4 site with eZ Demo frontend.

      1. Add the following twig template at vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/full/file.html.twig:

      {#
          File (test) - full view
      #}
       
      {% extends "eZDemoBundle::pagelayout.html.twig" %}
       
      {% block content %}
          <h1>File: {{ ez_field_value(content, "file").uri }}</h1>
          <br><a href="{{ ez_field_value(content, "file").uri }}">Link</a>
      {% endblock %}
      

      2. Add the file template definition on vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/config/ezdemo.yml after the article template definition:

                      file:
                          controller: "eZDemoBundle:Demo:showArticle"
                          template: "eZDemoBundle:full:file.html.twig"
                          match:
                              Identifier\ContentType: [file]
      

      3. Clear all caches
      4. Login to the administration backend and create a new File content object
      5. Add a .PDF file to it, and publish it
      6. From your eZ Demo frontend access the File content object you just created
      7. Click on the link on page to access to PDF

      You will get a Symfony error as follows:

      Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf
      

        Issue Links

          Activity

          Hide
          Bertrand Dunogier added a comment -

          Hello Ricardo. You forgot to attach the stack trace by the way.

          Show
          Bertrand Dunogier added a comment - Hello Ricardo. You forgot to attach the stack trace by the way.
          Hide
          Ricardo Correia (Inactive) added a comment -

          Hi Bertrand Dunogier,

          Here's the complete error from the log:

          [2015-03-04 11:03:48] request.CRITICAL: Uncaught PHP Exception eZ\Publish\Core\Base\Exceptions\InvalidArgumentException: "Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf" at /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php line 386 {"exception":"[object] (eZ\\Publish\\Core\\Base\\Exceptions\\InvalidArgumentException(code: 0): Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf at /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php:386)"} []
          

          And here's the stack trace:

          [1] eZ\Publish\Core\Base\Exceptions\InvalidArgumentException: Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf
              at n/a
                  in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php line 386
           
              at eZ\Publish\Core\IO\IOService->removeUriPrefix('original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf')
                  in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/TolerantIOService.php line 109
           
              at eZ\Publish\Core\IO\TolerantIOService->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf')
                  in /var/www/ezpublish54/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php line 39112
           
              at eZPublishCoreIOTolerantIOService_00000000419aa4f5000000007b8c0d35->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf')
                  in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/Image/IO/Legacy.php line 154
           
              at eZ\Publish\Core\FieldType\Image\IO\Legacy->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf')
                  in /var/www/ezpublish54/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php line 38794
           
              at eZPublishCoreFieldTypeImageIOLegacy_00000000419aa6c6000000007b8c0d35->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf')
                  in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Bundle/EzPublishIOBundle/EventListener/StreamFileListener.php line 62
           
              at eZ\Bundle\EzPublishIOBundle\EventListener\StreamFileListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
                  in  line 
           
              at call_user_func(array(object(StreamFileListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php line 61
           
              at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher))
                  in  line 
           
              at call_user_func(object(WrappedListener), object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 164
           
              at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(GetResponseEvent))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 53
           
              at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php line 170
           
              at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php line 112
           
              at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 126
           
              at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 66
           
              at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 64
           
              at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
                  in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 186
           
              at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
                  in /var/www/ezpublish54/web/index.php line 77
          

          Show
          Ricardo Correia (Inactive) added a comment - Hi Bertrand Dunogier , Here's the complete error from the log: [2015-03-04 11:03:48] request.CRITICAL: Uncaught PHP Exception eZ\Publish\Core\Base\Exceptions\InvalidArgumentException: "Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf" at /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php line 386 {"exception":"[object] (eZ\\Publish\\Core\\Base\\Exceptions\\InvalidArgumentException(code: 0): Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf at /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php:386)"} [] And here's the stack trace: [1] eZ\Publish\Core\Base\Exceptions\InvalidArgumentException: Argument '$id' is invalid: Prefix images not found in original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf at n/a in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/IOService.php line 386   at eZ\Publish\Core\IO\IOService->removeUriPrefix('original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf') in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/IO/TolerantIOService.php line 109   at eZ\Publish\Core\IO\TolerantIOService->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf') in /var/www/ezpublish54/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php line 39112   at eZPublishCoreIOTolerantIOService_00000000419aa4f5000000007b8c0d35->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf') in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/FieldType/Image/IO/Legacy.php line 154   at eZ\Publish\Core\FieldType\Image\IO\Legacy->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf') in /var/www/ezpublish54/ezpublish/cache/dev/ezpublishDevDebugProjectContainer.php line 38794   at eZPublishCoreFieldTypeImageIOLegacy_00000000419aa6c6000000007b8c0d35->loadBinaryFileByUri('/var/ezdemo_site/storage/original/application/deccb8d2bfc81d6da0df8eb956d83a17.pdf') in /var/www/ezpublish54/vendor/ezsystems/ezpublish-kernel/eZ/Bundle/EzPublishIOBundle/EventListener/StreamFileListener.php line 62   at eZ\Bundle\EzPublishIOBundle\EventListener\StreamFileListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher)) in line   at call_user_func(array(object(StreamFileListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php line 61   at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher)) in line   at call_user_func(object(WrappedListener), object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 164   at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(GetResponseEvent)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 53   at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php line 170   at Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php line 112   at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 126   at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 66   at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 64   at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) in /var/www/ezpublish54/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 186   at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) in /var/www/ezpublish54/web/index.php line 77
          Hide
          Bertrand Dunogier added a comment - - edited

          Actually, I've been thinking while working on that...

          For this particular case, the only fix right now is to add a rewrite rule that allows var/site/storage/original to pass through. We have another issue when DFS is involved, but this message is a side effect, as we aren't even supposed to end up in this listener:

          RewriteRule ^/var/storage/original/.* - [L]
          RewriteRule ^/var/[^/]+/storage/original/.* - [L]
          

          One issue with this is that it doesn't check for permissions. We need content/download for that, indeed.

          Show
          Bertrand Dunogier added a comment - - edited Actually, I've been thinking while working on that... For this particular case, the only fix right now is to add a rewrite rule that allows var/site/storage/original to pass through. We have another issue when DFS is involved, but this message is a side effect, as we aren't even supposed to end up in this listener: RewriteRule ^/var/storage/original/.* - [L] RewriteRule ^/var/[^/]+/storage/original/.* - [L] One issue with this is that it doesn't check for permissions. We need content/download for that, indeed.
          Hide
          Bertrand Dunogier added a comment -

          Here's what engineering suggests:

          First, we send the rewrite rule workaround to the customer. We specify that it is a workaround, and that it will make all the binary files publicly available. There won't be any links to them by default, and their name contains a checksum, but it must be known.

          On our side, we prioritize the implementation of Binary Files download (EZP-23550).

          Please let us know.

          Show
          Bertrand Dunogier added a comment - Here's what engineering suggests: First, we send the rewrite rule workaround to the customer. We specify that it is a workaround, and that it will make all the binary files publicly available. There won't be any links to them by default, and their name contains a checksum, but it must be known. On our side, we prioritize the implementation of Binary Files download ( EZP-23550 ). Please let us know.
          Hide
          Bertrand Dunogier added a comment -

          As discussed during wednesday may 20th 3rd line meeting, we will fix the 5.4 issue with a documentation update. The overall idea is to make it clear that the uri property from BinaryFile or Media Field Value can not be used to download a file. The official workaround is to use legacy's content/download, as done in the default field render template for media and binaryfile.

          New stack binary files download will be implemented in Platform 1.0, but not backported to eZ Publish Platform 5.x.

          Show
          Bertrand Dunogier added a comment - As discussed during wednesday may 20th 3rd line meeting, we will fix the 5.4 issue with a documentation update. The overall idea is to make it clear that the uri property from BinaryFile or Media Field Value can not be used to download a file. The official workaround is to use legacy's content/download, as done in the default field render template for media and binaryfile. New stack binary files download will be implemented in Platform 1.0, but not backported to eZ Publish Platform 5.x.
          Hide
          Rui Silva (Inactive) added a comment -

          Tested and approved by QA for the suggested fix, and for the doc provided.
          It has been verified that the issue occurs as reported, and the suggested solution solves the issue (as a workaround), as well as all discussed security situations also happen.
          This issue is not provided with a patch for its solution, instead, a set of rewrite rules for the webserver are provided.

          Show
          Rui Silva (Inactive) added a comment - Tested and approved by QA for the suggested fix, and for the doc provided. It has been verified that the issue occurs as reported, and the suggested solution solves the issue (as a workaround), as well as all discussed security situations also happen. This issue is not provided with a patch for its solution, instead, a set of rewrite rules for the webserver are provided.

            People

            • Assignee:
              Unassigned
              Reporter:
              Ricardo Correia (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: