WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#37635 new defect (bug)

BUG in get_option

Reported by: tazotodua Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: reporter-feedback
Focuses: Cc:
PR Number:

Description

in wp_options, i had saved this large serialized string:

http://pastebin.com/raw/hxwETuHX

however, when i run get_option("option_name") it returns false...
i have spent time and found out, that it's because that get_option tries to unserialize it and return the result, but it have problems while unserializing.

then i decided to manually grab the value and unserialize by hand.. and i succeeded!


$raw_data=$wpdb->get_var("Select option_value from wp_options Where option_name='option_name'");

unserialize(Serialized_Fixer($raw_data));


function Serialized_Fixer($serialized_string){
    // securities
    if ( !preg_match('/^[aOs]:/', $serialized_string) ) return $serialized_string;
    if ( @unserialize($serialized_string) !== false ) return $serialized_string;
        
        return
        preg_replace_callback(
                '/s\:(\d+)\:\"(.*?)\";/s', 
                function ($matches){    return 's:'.strlen($matches[2]).':"'.$matches[2].'";';  },
                $serialized_string )
        ;
}

and that worked!
this is seriously a bug of WP!
please fix it! thanks!

Change History (6)

#1 @tazotodua
3 years ago

sorry for bad formatting, but you will understand my explanation.

Version 0, edited 3 years ago by tazotodua (next)

#2 follow-up: @SergeyBiryukov
3 years ago

  • Component changed from General to Options, Meta APIs

Previously: #18007, #21109.

Could not reproduce, this test script displays correct data on my install:

require 'wp-load.php';

$content = file_get_contents( 'http://pastebin.com/raw/hxwETuHX' );
$content = unserialize( $content );

add_option( 'get_option_unserialize_test', $content );

var_dump( get_option( 'get_option_unserialize_test' ) );

delete_option( 'get_option_unserialize_test' );

What is the DB_CHARSET value in your wp-config.php file and the actual DB charset?

This appears to be a misconfiguration issue like in #21109 or ticket:6784:3.

#3 @tazotodua
3 years ago

maybe you are right. I will check that.

#4 @swissspidy
3 years ago

  • Keywords reporter-feedback added

#5 @tazotodua
3 years ago

@swissspidy well, actually I've made mistake while I gave the example data above. As it's english, it doesnt have problem, but here is actual example of get_option value (serialized, saved in phpmyadmin): http://pastebin.com/raw/i4YVxKpK

please, try your above method same this data.

p.s. what's interesting, the get_option for that data works on my Production website, but on localhost it doesnt work (returns false).

the DB are both InnoDB (latin1_swedish_ci) and tables are both utf8mb4_unicode_ci.

what's more, wp-config are same for both.

#6 in reply to: ↑ 2 @tazotodua
2 years ago

Replying to SergeyBiryukov:

@swissspidy well,
please, try your above method this data - http://pastebin.com/raw/i4YVxKpK
p.s. what's interesting, the get_option for that data works on my Production website, but on localhost it doesnt work (returns false).
the DB are both InnoDB (latin1_swedish_ci) and tables are both utf8mb4_unicode_ci.
what's more, wp-config are same for both.

Note: See TracTickets for help on using tickets.