ssahara / dw-plugin-NumberedHeadings

Prepend tiered numbers as indexes for hierarchical headings
https://www.dokuwiki.org/plugin:numberedheadings
GNU General Public License v2.0
0 stars 2 forks source link

Crashes #1

Closed quirkiest closed 5 years ago

quirkiest commented 5 years ago

The new syntax.php caused crashes in our Dokuwiki - as far as we can tell it seems to chew up huge amounts of memory, where the old version did not. We have quite a large page with lots of headings.

Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in C:\DokuWiki Stick\dokuwiki\lib\plugins\numberedheadings\syntax.php on line 115

graham-macleod commented 5 years ago

I can confirm I also get this error.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217736 bytes) in /var/www/html/lib/plugins/numberedheadings/syntax.php on line 115

Worth pointing out, it doesn't happen on all pages. Also, I can't tell what the difference between a page that works and a page that doesn't work is. The page that crashes isn't even all that large.

ssahara commented 5 years ago

I could not reproduce the memory error, however have modified code slightly to use array_slice instead of for-loop to get tiered numbers.

$ diff -up syntax.php.20190103 syntax.php
--- syntax.php.20190103 2019-05-25 21:13:06.832121365 +0900
+++ syntax.php  2019-05-27 16:18:36.174030851 +0900
@@ -110,11 +110,8 @@ class syntax_plugin_numberedheadings ext
         }

         // build tiered numbers for hierarchical headings
-        $numbers = [];
-        for ($i = $this->startlevel; $i <= $level; $i++) {
-            $numbers[] = $this->headingCount[$i];
-        }
-        if ($numbers) {
+        if ($this->startlevel <= $level) {
+            $numbers = array_slice($this->headingCount, $this->startlevel -1, $level - $this->startlevel +1);
             $tieredNumber = implode('.', $numbers);
             if (count($numbers) == 1) {
                 // append always tailing dot for single tiered number
graham-macleod commented 5 years ago

@ssahara I no longer get the fatal error, however I do get multiple warnings (10 to be exact) with the following text...

Warning: A non-numeric value encountered in /var/www/html/lib/plugins/numberedheadings/syntax.php on line 114

The following is what gets output in the headings list. It's not obvious from what I have put below but I have this set so that level 2 is the starting heading, and the other two configuration options are unticked. The very last heading is a level 3 heading.

Also, I'm using the bootstrap theme.

1. xxxxx
2. xxxxx
3. xxxxx
3.1 xxxxx
4. xxxxx
5. xxxxx
6. xxxxx
7. xxxxx
0. xxxxx
0. xxxxx
0. xxxxx
0. xxxxx
0. xxxxx
ssahara commented 5 years ago

Updated the plugin with $this->startlevel = (int) substr($match, -3, 1); to avoid possible non-numeric value warnings.

graham-macleod commented 5 years ago

@ssahara Just to update you. The new version didn't fix the issue but I did some further digging an it looks like the point at which the numbers start returning zero, the heading markup (i.e. "=====") was prefixed with a space. This then caused all the headings from that point onward to return 0.

I have removed this space and it's working ok now.

ssahara commented 5 years ago

@graham-macleod, Thanks your feedback. Release 2019-06-15 should handle correctly a space before heading markup.