nosilver4u / ewww-image-optimizer

Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
https://ewww.io
GNU General Public License v3.0
114 stars 26 forks source link

Warning on array value due to improper condition order #340

Open jameshgordy opened 1 week ago

jameshgordy commented 1 week ago

https://github.com/nosilver4u/ewww-image-optimizer/blob/7f4173204f477dc4976ff3b6033ec8b27145d764/common.php#L8216

My project was receiving extensive warnings like this:

Undefined array key 0 in /projects/xyz/public_html/wp-content/plugins/ewww-image-optimizer/common.php on line 8174

This is due to validating an array value that is being request potentially after an existence check - as per PHP Operator Precedence which indicates the logic is left to right due to the || operator.

A preferred option would be adding a falsifiable alternative perhaps?

if ( ! is_array( $duplicates ) || ! is_array( $duplicates[0] ?? false ) ) { return false; }

nosilver4u commented 1 week ago

Thanks for reporting that, we'll get it fixed soon! I reworked that function a while back, so I suspect this bug slipped in then.