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

libraries/classes/Display/Results.php not guarding against null metadata in getHeaderTablesForColumns #17046

Closed
jemenake opened this issue Jul 29, 2021 · 11 comments
Assignees
Labels
Bug A problem or regression with an existing feature
Projects
Milestone

Comments

@jemenake
Copy link

Describe the bug

I was getting a red popup about a 500 error when trying to browse just a certain table in a certain db. I eventually tracked it down to this in the logs:

[Wed Jul 28 ... ] [php7:error] [pid ...] [client ... ] PHP Fatal error:
Uncaught TypeError: htmlspecialchars() expects parameter 1 to be string, null given in /usr/share/phpMyAdmin/libraries/classes/Display/Results.php:2001
Stack trace:
#0 /usr/share/phpMyAdmin/libraries/classes/Display/Results.php(2001): htmlspecialchars(NULL)
#1 /usr/share/phpMyAdmin/libraries/classes/Display/Results.php(1676): PhpMyAdmin\\Display\\Results->getSortOrderLink('', NULL, 'index.php?route...', 'index.php?route...')
#2 /usr/share/phpMyAdmin/libraries/classes/Display/Results.php(1057): PhpMyAdmin\\Display\\Results->getOrderLinkAndSortedHeaderHtml(NULL, Array, Array, NULL, 'SELECT * FROM `...', 25, '', Array, Array, NULL)
#3 /usr/share/phpMyAdmin/libraries/classes/Display/Results.php(1173): PhpMyAdmin\\Display\\Results->getTableHeadersForColumns(Array, Array, Array, Array, Array, false, 'SELECT * FROM `...')
#4 /usr/share/phpMyAdmin/libraries/classes/Display/Results.php(4166): PhpMyAdmin\\Display\\Results->getTableHeaders(Array, Array, 'SELECT * FROM `...', Array, Array, Array, false)
#5 /usr/share/phpMyAdmin/ in /usr/share/phpMyAdmin/libraries/classes/Display/Results.php on line 2001

It looks like, in getHeaderTablesForColumns, $fields_meta is fetched, and there's no subsequent guard against fields being null (in this case ->name field being null for one of the entries).

As an experiment, I cloned the table, and phpmyadmin does fine with the cloned table.

Here's where things got weird. Suspecting the problem was with a particular table column, I started trying "SELECT col1 FROM ...", then "SELECT col1, col2 FROM ...", etc. expecting to eventually include a column to make it crash. In fact, I was able to enumerate all of the columns without encountering an error. And then I was able to do a regular browse of the table (no more red popup). Now, however, I'm only being shown the first two column headers.

To Reproduce

I'm not sure what metadata is causing this. From looking through the functions along the stack trace, I suspect that the original cause was a preference (like default sort column?) referencing a column that was no longer there. This bug happened sometime around when I upgraded from PHP 7.2 to 7.4 but and did some table alterations.

My next diagnostic step would be to delete as many of the preferences referencing the table that I can find in the pma_* tables, but I wanted to hold off on that in case the engineers want me to test something else, first.

Expected behavior

One clicks on a table name and sees the rows and columns. Even after I got this to happen, many of the column headers were missing.

Screenshots

Screen Shot 2021-07-28 at 19 32 23

Server configuration

CentOS 7
MariaDB 10.5.11
PHP 7.4.22
Apache 2.4.6
phpMyAdmin 5.1.1

Client configuration

Chrome 92.0.4515.107
MacOS 11.4 (Intel)

@jemenake
Copy link
Author

After experimenting further, I looked at the 'column visibility' drop-down menu, and only those first two columns were selected, so (even though I don't know how the others got turned off) it appears that the headers were properly following the selections, while the column data was not.
Turning the column visibility back on brought the headers back.
Turning the column visibility off, afterwards, properly hid the headers and the data, as is the expected behavior.

So, somehow, the column visibility metadata can get into a strange state where the data columns are still viewable while the headers are not.

@williamdes
Copy link
Member

Thank you so much for the report @jemenake :)

Would you be able to to reproduce this issue on one of our demo servers?

Demo servers (root, no password)

@williamdes williamdes added Bug A problem or regression with an existing feature question Used when we need feedback from the submitter or when the issue is a question about PMA labels Jul 29, 2021
@williamdes williamdes added this to Needs triage in Questions via automation Jul 29, 2021
@williamdes williamdes moved this from Needs triage to Needs a second check to be a bug in Questions Jul 29, 2021
@sparcbr
Copy link

sparcbr commented Aug 6, 2021

I got the same error, and the only thing I did different was swapping two columns in the browsing view. Now I can't fix it.

Edit: I swapped back the column but the error continues, so I guess that was not it..

@williamdes williamdes added this to the 5.1.2 milestone Aug 6, 2021
@williamdes
Copy link
Member

Hi @sparcbr
Could you also post your stacktrace ?

@sparcbr
Copy link

sparcbr commented Aug 6, 2021

This error only occurs if I use a join:

Fatal error: Uncaught TypeError: htmlspecialchars() expects parameter 1 to be string, null given in /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php:2001
	Stack trace:
	#0 /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php(2001): htmlspecialchars(NULL)
	#1 /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php(1676): PhpMyAdmin\Display\Results->getSortOrderLink('', NULL, 'index.php?route...', 'index.php?route...')
	#2 /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php(1057): PhpMyAdmin\Display\Results->getOrderLinkAndSortedHeaderHtml(NULL, Array, Array, NULL, 'SELECT\r\n `pr...', 25, '', Array, Array, NULL)
	#3 /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php(1173): PhpMyAdmin\Display\Results->getTableHeadersForColumns(Array, Array, Array, Array, Array, false, 'SELECT\r\n `pr...')
	#4 /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php(4166): PhpMyAdmin\Display\Results->getTableHeaders(Array, Array, 'SELE in /home/sparc/repos/phpmyadmin.git/libraries/classes/Display/Results.php on line 2001

@sparcbr
Copy link

sparcbr commented Aug 6, 2021

I couldn't log to the demo server with the credentials provided (root without a password). Tried both 5.1.x-dev and 5.2.0-dev

@jemenake
Copy link
Author

jemenake commented Aug 7, 2021

I couldn't either. I'm going to try sparcbr's suggestion about changing the order of columns (because I think I was also doing that before this issue happened), and, if I can replicate the issue, I'll post a SQL file with some specific instructions on how to make the problem happen.

@ibennetch
Copy link
Member

@sparcbr I have fixed the demo server. Thanks for pointing out that there was a problem.

@jemenake
Copy link
Author

jemenake commented Aug 9, 2021

Edit: I swapped back the column but the error continues, so I guess that was not it..

Can you try limiting your columns (instead of "SELECT *", if that's what you're doing) to just a single one, and see if you can gradually add more columns?

@williamdes
Copy link
Member

williamdes commented Aug 10, 2021

Hi @sparcbr

I truly believe there is a bug give the traces that where sent here, but I can not figure out how to reproduce this
Could you please give us your query without changing anything ?

I could push a fix but this would not cover all the other possible cases in our code base :)

@williamdes williamdes self-assigned this Aug 22, 2021
@williamdes williamdes removed the question Used when we need feedback from the submitter or when the issue is a question about PMA label Aug 22, 2021
@williamdes williamdes removed this from Needs a second check to be a bug in Questions Aug 22, 2021
@williamdes williamdes added this to Needs triage in issues via automation Aug 22, 2021
@williamdes williamdes moved this from Needs triage to to be fixed soon in issues Aug 22, 2021
williamdes added a commit that referenced this issue Aug 22, 2021
Signed-off-by: William Desportes <williamdes@wdes.fr>
issues automation moved this from to be fixed soon to Closed Aug 22, 2021
@williamdes
Copy link
Member

I pushed 8f4514c to remove the error, can someone confirm that it also works fine ?
Any more debug to find the root cause would be very welcome :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A problem or regression with an existing feature
Projects
issues
  
Closed
Development

No branches or pull requests

4 participants