Git Product home page Git Product logo

Comments (8)

kevincupp avatar kevincupp commented on May 22, 2024

Sorry for the delay on that. See if this breaks the world:

--- a/system/ee/legacy/libraries/api/Api_channel_fields.php
+++ b/system/ee/legacy/libraries/api/Api_channel_fields.php
@@ -1537,8 +1537,10 @@ class Api_channel_fields extends Api {
                $pfield_chunk = array();
                $offset = 0;
                $field_name = $prefix.$field_name;
+               $modifier = '';
+               $end = strpos($tagdata, LD.'/'.$field_name, $offset);

-               while (($end = strpos($tagdata, LD.'/'.$field_name, $offset)) !== FALSE)
+               while ($end !== FALSE)
                {
                        // This hurts soo much. Using custom fields as pair and single vars in the same
                        // channel tags could lead to something like this: {field}...{field}inner{/field}
@@ -1582,7 +1584,8 @@ class Api_channel_fields extends Api {
                                $pfield_chunk[] = $chunk_array;
                        }

-                       $offset = $end + 1;
+                       $end = strpos($tagdata, LD.'/'.$field_name.$modifier.RD, $offset);
+                       $offset = (int) $end + 1;
                }

                return $pfield_chunk;

from expressionengine.

litzinger avatar litzinger commented on May 22, 2024

I forgot all about this until now. I'll try to investigate this soon.

from expressionengine.

litzinger avatar litzinger commented on May 22, 2024

Took a stab and added this to my local copy of a large site and it's eventually running out of memory somewhere. I undo the change and everything returns to normal.

Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)

edit: this is on a page that does not have any issues with tag pairs with similar prefixes, but it does have a lot of tag pairs in general (e.g. Bloqs fields)

from expressionengine.

kevincupp avatar kevincupp commented on May 22, 2024

Poo, thanks for testing. I'm having trouble getting that to happen on my end, would you be able to send me that template text?

from expressionengine.

kevincupp avatar kevincupp commented on May 22, 2024

Thanks for the assist, had some colliding variables that were causing an infinite loop. Here's a slightly modified diff:

--- a/system/ee/legacy/libraries/api/Api_channel_fields.php
+++ b/system/ee/legacy/libraries/api/Api_channel_fields.php
@@ -1537,14 +1537,17 @@ class Api_channel_fields extends Api {
                $pfield_chunk = array();
                $offset = 0;
                $field_name = $prefix.$field_name;
+               $end = strpos($tagdata, LD.'/'.$field_name, $offset);

-               while (($end = strpos($tagdata, LD.'/'.$field_name, $offset)) !== FALSE)
+               while ($end !== FALSE)
                {
                        // This hurts soo much. Using custom fields as pair and single vars in the same
                        // channel tags could lead to something like this: {field}...{field}inner{/field}
                        // There's no efficient regex to match this case, so we'll find the last nested
                        // opening tag and re-cut the chunk.

+                       $modifier = '';
+
                        if (preg_match("/".LD."{$field_name}((?::\S+)?)(\s.*?)?".RD."(.*?)".LD.'\/'."{$field_name}\\1".RD."/s", $tagdata, $matches, 0, $offset))
                        {
                                $chunk = $matches[0];
@@ -1563,8 +1566,8 @@ class Api_channel_fields extends Api {
                                        $params = $match[1][$idx];

                                        // Cut the chunk at the last opening tag
-                                       $offset = strrpos($chunk, $tag);
-                                       $chunk = substr($chunk, $offset);
+                                       $chunk_offset = strrpos($chunk, $tag);
+                                       $chunk = substr($chunk, $chunk_offset);
                                        $chunk = strstr($chunk, LD.$field_name);
                                        $content = substr($chunk, strlen($tag), -strlen(LD.'/'.$field_name.RD));
                                }
@@ -1582,7 +1585,8 @@ class Api_channel_fields extends Api {
                                $pfield_chunk[] = $chunk_array;
                        }

-                       $offset = $end + 1;
+                       $end = strpos($tagdata, LD.'/'.$field_name.$modifier.RD, $offset);
+                       $offset = (int) $end + 1;
                }

                return $pfield_chunk;

from expressionengine.

litzinger avatar litzinger commented on May 22, 2024

That fix didn't cause an infinite loop and the page loads fine for me, but I don't have a test case setup right now for the exact scenario reported (the similar prefixes), so I can't confirm that at the moment. I'll try to do that tonight.

from expressionengine.

litzinger avatar litzinger commented on May 22, 2024

Kevin, a co-worker just ran into this issue where the blocks were being duplicated as noted in the original report, and he just added your fix to EE and the issue is resolved. I think it's safe to say your patch is safe to merge.

If it helps, before your fix is applied, the tag pairs in the following order did work

{blocks_statistic}{/block_statistic}
{blocks_statistic_group}{/blocks_statistic_group}

But this tag pair order did not work

{blocks_statistic_group}{/blocks_statistic_group}
{blocks_statistic}{/block_statistic}

from expressionengine.

kevincupp avatar kevincupp commented on May 22, 2024

Thanks for trying this out! It's in for the next release.

from expressionengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.