• Resolved japonicus

    (@japonicus)


    On pages with a large number of download links I’d noticed that page loads were very slow (> 20s). I traced this to a slow query when processing Download tags:

    SELECT tefr_posts.*
    FROM tefr_posts
    WHERE 1=1
    AND tefr_posts.post_type = 'dlm_download_version'
    AND (tefr_posts.post_status = 'publish'
    OR tefr_posts.post_status = 'acf-disabled'
    OR tefr_posts.post_status = 'private')
    ORDER BY tefr_posts.menu_order ASC

    (this unconstrained query pulls all download posts not just a single one, bound by id)

    triggered by

    WP_Query->get_posts()
    wp-includes/class-wp-query.php:3034
    WP_Query->query()
    wp-includes/class-wp-query.php:3465
    DLM_WordPress_Version_Repository->retrieve()
    wp-content/plugins/download-monitor/src/Version/WordPressVersionRepository.php:92
    DLM_WordPress_Version_Repository->retrieve_single()
    wp-content/plugins/download-monitor/src/Version/WordPressVersionRepository.php:69
    DLM_Shortcodes->download()
    wp-content/plugins/download-monitor/src/Shortcodes.php:114
    do_shortcode_tag()
    wp-includes/shortcodes.php:343
    preg_replace_callback()
    wp-includes/shortcodes.php:343
    do_shortcode()

    The problem is that in DLM_Shortcodes->download() $version_id is initialised to ” (empty string) rather than to null if $version is unset.

    isset() treats ” as set so the check for isset and != 0 passes (when it was clearly intended to fail).

    if ( isset( $version_id ) && 0 != $version_id )

    That allows an unbounded query for all dlm_download_version posts rather than just for a single id.

    The solution is to initialise $version_id to null rather than ” at line 78

    extract( shortcode_atts( array(
    			'id'         => '',
    			'autop'      => false,
    			'template'   => dlm_get_default_download_template(),
    			'version_id' => null // was ''
    			'version'    => ''
    		), $atts ) );

    thanks,

    Tom

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter japonicus

    (@japonicus)

    I’ve just realised that this is a PHP 8 specific bug.

    In PHP 7.4 and earlier 0 != ” is FALSE whereas this is TRUE in PHP 8

    Hello @japonicus ,

    Thank you very much for reporting this and for giving a solution. I have issued this on github in order for our dev team to take a look, and probably in the next update the fix will be deployed.
    Again, thank you very much.

    Kind Regards!
    Razvan

    Miha

    (@mplusb)

    This topic will be marked as resolved as we have an open ticket on GitHub regarding this. Please keep in mind that the ‘resolved’ status is only for this support thread, not the issue on GitHub.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Bug in DLM_Shortcodes::download()’ is closed to new replies.