Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NULL character found in serialized string

I am unable to unserialize() a backtrace that I serialize()'d and saved to a text file. I cannot also copy-paste the string, it only copies the data before NULL so I am unable to unserialize it back in PHP.

Here's a small excerpt of what it looks like in Notepad++

enter image description here

Any ideas how to unserialize this?

Note: I am using error_log($backtrace, 3, 'file.log'); to save the file, then simply open in Notepad++ to copy-paste but I can't copy past the NULL character.

like image 698
IMB Avatar asked Jul 30 '12 20:07

IMB


1 Answers

So the serialize function identifies member variables with the syntax null*null as you are showing here.

The null character is encoded in a string as \0 and is not usually displayed in output. To unserialize you will need to convert those "null" text back to \0.

When I write a serialized array I run it through a function that converts \0 to [NULL].

$string = str_replace("\0","[NULL]",$string);

Then when you're ready to unserialize you can just do the opposite

$string = str_replace("[NULL]","\0",$string);
like image 86
danielson317 Avatar answered Nov 10 '22 08:11

danielson317