I'm not certain what changed between 7.x-1.6 and 7.x-1.8 that caused this error, as the older plugin worked fine. This turned into a wild-goose chase of a sort, till I realized that the fault (maybe?) lies with the CKEditor plugin. The issue is:

    echo file_create_url($content['field_file']);

Results in an out of memory error coming from token.tokens.inc:895. So I put in "breakpoint" to perform a debug backtrace before the offending block.

  // Break on >75MB memory usage
  if (memory_get_usage(true) > 75 * 1048576) {
    ob_end_clean();
    echo '<pre>&#039;;&#10;    debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);&#10;    echo &#039;</pre>';
    die;
  }

And you can pretty clearly find the infinite recursion with that output. I sorted this so that order of execution goes from top to bottom, rather than the default debug_print_backtrace() output.

file_create_url() called at [sites/all/modules/ckeditor/ckeditor.module:605]
DrupalStorageStreamWrapper->getExternalUrl() called at [includes/all.inc:404]
Storage->serveURL() called at [sites/all/modules/storage_api/core_bridge/storage_core_bridge.module:701]
Storage->access() called at [sites/all/modules/storage_api/storage.inc:383]
module_invoke() called at [sites/all/modules/storage_api/storage.inc:142]
call_user_func_array() called at [includes/all.inc:866]
storage_core_bridge_storage_access()
file_download_access() called at [sites/all/modules/storage_api/core_bridge/storage_core_bridge.module:437]
file_download_headers() called at [includes/all.inc:2070]
ckeditor_file_download() called at [includes/all.inc:2035]
file_create_url() called at [sites/all/modules/ckeditor/ckeditor.module:605]

The problem is, when checking if the URI is accessible storage_core_bridge_storage_access() invokes file_download_access(), which goes to modules implementing a hook. CKEditor then picks it up and calls file_create_url() once more—and bingo, infinite recursion!

My fix, temporarily, is to patch the ckeditor_file_download() hook to only download public/private/http/https URLs.

function ckeditor_file_download($uri) {
  if (in_array(parse_url($uri, PHP_URL_SCHEME), array('public', 'private', 'http', 'https'))
      && ($path = file_create_url($uri)))
  {

However, I'm not 100% certain: is the fault CKEditor's, or Storage? Since I've never had this issue, on multiple sites, till I upgraded the Storage API I'm thinking its a potential issue with Storage. Especially since other modules could make the same mistake and call file_create_url() from within hook_file_download().

At the least, I figured that posting this would probably help someone else.

Comments

krebor created an issue. See original summary.

Perignon’s picture

Status: Active » Closed (duplicate)
Parent issue: » #2549535: Infinite loop on file access check with CKEditor Module

We have beat this to death in the issue queue. Just make sure you search an issue queue before you spend too much time doing a writeup like you did. You just wasted a bunch of your time!

See the parent issue I have attached to this and you can follow the links to the other issues. The issue is with CKEditor module.