Skip to content

Conversation

@SandiyosDev
Copy link
Contributor

@SandiyosDev SandiyosDev commented Mar 17, 2025

Summary

While running PHP 8.2.5, and visiting /wp-admin/site-health.php, the following fatal error occurred in our instance:

strlen(): Argument #1 ($string) must be of type string, array given

this was triggered in perflab_aao_query_autoloaded_options() whenever wp_load_alloptions() returned an array or object, and the code called strlen() on that non-string, and since some object caching solutions can return unserialized data, it caused the fatal error above in PHP 8+

Addresses #

this PR updates perflab_aao_query_autoloaded_options() to wrap $option_value with maybe_serialize() before measuring its length to make sure it’s always a valid string

Relevant technical choices

if the value is already a string, the function does nothing, if it’s an array or object, it gets validly serialized

@github-actions
Copy link

github-actions bot commented Mar 17, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @SandiyosDev.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: SandiyosDev.

Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only labels Mar 17, 2025
@codecov
Copy link

codecov bot commented Mar 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.21%. Comparing base (61fa5d2) to head (fce7677).
Report is 8 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #1934   +/-   ##
=======================================
  Coverage   71.20%   71.21%           
=======================================
  Files          86       86           
  Lines        6998     7000    +2     
=======================================
+ Hits         4983     4985    +2     
  Misses       2015     2015           
Flag Coverage Δ
multisite 71.21% <100.00%> (+<0.01%) ⬆️
single 40.71% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SandiyosDev
Copy link
Contributor Author

I wish to remain as an unlinked contributor for the time being, I'm only here to fix an issue I encountered.

@westonruter
Copy link
Member

@SandiyosDev Are you using Docket Cache by any chance?

This came up before: #1237.

It was addressed in perflab_aao_autoloaded_options_size() via #1238, but apparently it wasn't also implemented in perflab_aao_query_autoloaded_options().

@SandiyosDev
Copy link
Contributor Author

Docket Cache

No, I switched our instance to using atec-cache-apcu from redis-cache since we're running a single instance

SandiyosDev and others added 2 commits March 17, 2025 16:32
…options/helper.php

Co-authored-by: Weston Ruter <westonruter@google.com>
…options/helper.php

Co-authored-by: Weston Ruter <westonruter@google.com>
@westonruter westonruter changed the title fix TypeError in perflab_aao_query_autoloaded_options by serializing non-scalar option values Fix TypeError in perflab_aao_query_autoloaded_options() by serializing non-scalar option values Mar 17, 2025
@westonruter westonruter added this to the performance-lab n.e.x.t milestone Mar 17, 2025
…options/helper.php

Co-authored-by: Weston Ruter <westonruter@google.com>
@westonruter
Copy link
Member

No, I switched our instance to using atec-cache-apcu from redis-cache since we're running a single instance

Thanks. Technically then it seems atec-cache-apcu is not correctly implemented because it is causing wp_load_alloptions() to return something other than an array of serialized string values, which WordPress does here normally. Docket Cache is doing the same thing. In any case, we should be hardened against this scenario since at least two object cache plugins seem to be doing this.

@westonruter
Copy link
Member

One thing that would nice to add is a test case for this as was added in #1238.

@SandiyosDev
Copy link
Contributor Author

One thing that would nice to add is a test case for this as was added in #1238.

@westonruter I'd agree with adding a test case for this PR, but I'm working through the GitHub web interface and codeserver with this PHP codebase binded, and since Codeserver is running in a non-PHP context, I can't properly validate my tests.
Could you assist me in adding the test case?

@westonruter
Copy link
Member

Yeah, someone can add a test if not me.

@westonruter westonruter merged commit dd21c41 into WordPress:trunk Mar 17, 2025
15 checks passed
@SandiyosDev
Copy link
Contributor Author

Yeah, someone can add a test if not me.

thank you very much westonruter, you can keep the credit

@SandiyosDev SandiyosDev deleted the patch-1 branch March 18, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants