Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined array key 3 in ./inc/media.php on line 1700 #4276

Open
dregad opened this issue May 1, 2024 · 7 comments · May be fixed by #4278
Open

Undefined array key 3 in ./inc/media.php on line 1700 #4276

dregad opened this issue May 1, 2024 · 7 comments · May be fixed by #4278
Labels

Comments

@dregad
Copy link
Contributor

dregad commented May 1, 2024

The problem

My wiki's error log is swamped with hundreds of occurrences of the following errors, every day.

E_WARNING: Undefined array key 3 in ./inc/media.php(1700)
E_WARNING: Trying to access array offset on value of type null in ./inc/media.php(1700)

I was initially not able to reproduce the problem, so I searched the web server's logs for more information and found out that most of these requests seem to be triggered by bots; analyzing the queries, I realized that the problem occurs when an unknown or unaccessible namespace is referenced when opening the media manager with the following URL

http://example.com/dokuwiki/doku.php?do=media&ns=XXX

Where XXX is the offending namespace (e.g. from my logs: wiki:backup, which does not exist)

Version of DokuWiki

2024-02-06a Kaos (reproducible in master @ 31afae8)

PHP Version

8.2.16

Webserver and version of webserver

No response

Browser and version of browser, operating system running browser

No response

Additional environment information

No response

Relevant logs and/or error messages

No response

@dregad dregad added the Bug label May 1, 2024
@dregad
Copy link
Contributor Author

dregad commented May 1, 2024

the problem occurs when an unknown or unaccessible namespace is referenced

This is not entirely true actually, something fishy is going on here...

Given the following namespaces hierarchy

+- root
   +- playground
   +- wiki

Accessing the URL http://example.com/dokuwiki/doku.php?do=media&ns=XXX

Value of XXX Result Comments
aaa Non-existing namespace aaa inserted before the first "real" namespace (playground)
zzz zzz namespace not listed in hierarchy, PHP warnings occur
qqq Non-existing namespace inserted between playground and wiki namespaces
playground playground namespace selected
playground:xxx Non-existing sub-namespace xxx inserted below playground
wiki:xxx Non-existing wiki:xxx namespace not listed in hierarchy, PHP warnings occur

@fiwswe
Copy link
Collaborator

fiwswe commented May 1, 2024

2024-02-14a Kaos

Not very likely ;-) But let's assume you meant 2024-02-06a Kaos.

I can not reproduce this using:
$ curl --url 'https://<myhostname>/doku.php?do=media&ns=wiki:xyz'
where the namespace wiki:xyz does not exist. I also tried aaa and wiki:xxx (which also don't exist) with the same result. But I do have a more complicated hierarchy of namespaces in the wiki I was using.

DW: 2024-02-06a Kaos
PHP: 8.3.6 (using PHP-FPM)

So whatever is going on, must be still more obscure.

@dregad
Copy link
Contributor Author

dregad commented May 1, 2024

2024-02-14a Kaos

Not very likely ;-) But let's assume you meant 2024-02-06a Kaos.

Indeed. Sorry about that, fixed.

I can not reproduce this [...] But I do have a more complicated hierarchy of namespaces in the wiki I was using.

Do you have any namespaces after wiki (in lexicographical order) ? The key is the namespace specified by ns parameter, which must be higher than your last namespace's name (i.e. strcmp('XXX', 'yournamespace') > 0)

@dregad
Copy link
Contributor Author

dregad commented May 1, 2024

I think I've nailed it. I'll submit a pull request shortly.

@fiwswe
Copy link
Collaborator

fiwswe commented May 1, 2024

Do you have any namespaces after wiki (in lexicographical order) ? The key is the namespace specified by ns parameter, which must be higher than your last namespace's name (i.e. strcmp('XXX', 'yournamespace') > 0)

No. I don't have any sub-namespaces in the wiki ns and my last root ns starts with a w So I tried the same thing with ns=xxx. Alas same result.

Note: I am seeing some unrelated warnings from the Discussion plugin which I have installed (not actively used except for a few test pages). I don't think these warnings have any bearing on your issue though.
PHP message: PHP Warning: Undefined array key "comment" in /dokuwiki/lib/plugins/discussion/action.php on line 222

@dregad
Copy link
Contributor Author

dregad commented May 1, 2024

I don't know what to say. This is consistently reproducible for me, with a fresh install of DokuWiki from Git master, with every plugin disabled.

@dregad
Copy link
Contributor Author

dregad commented May 1, 2024

OK let me rephrase that.

With master branch, I get the PHP warnings, but the temporary namespace is added.

image

I was actually testing with a commit fixing the PHP warning that started this whole thing (adding an array_key_exists() check to the while loop in media_nstree()). In this case, no more warnings but the temp namespace is gone.

image

dregad added a commit to dregad/dokuwiki that referenced this issue May 1, 2024
E_WARNING: Undefined array key 3 in ./inc/media.php(1700)
E_WARNING: Trying to access array offset on value of type null in ./inc/media.php(1700)

This happens when the media manager is called with ns parameter set to
a value higher than the last namespace defined in the wiki.

Fixes dokuwiki#4276
dregad added a commit to dregad/dokuwiki that referenced this issue May 1, 2024
When the media manager is called with ns parameter set to a value higher
than the last namespace defined in the wiki, the non-existing namespace
is not added to the hierarchy.

This behavior is not consistent with what happens when the namespace's
name is lower. In this case, an entry is inserted in the tree at the
appropriate location.

Fixed by appending the temporary namespace at the end of the tree if it
was not inserted by the search loop.

Fixes dokuwiki#4276
@dregad dregad linked a pull request May 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants