php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11749 Unserialize dies with Apache Module but is FINE with CGI
Submitted: 2001-06-27 12:33 UTC Modified: 2001-06-29 04:17 UTC
From: btanner at home dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.6 OS: Win32 (Win 2k)
Private report: No CVE-ID: None
 [2001-06-27 12:33 UTC] btanner at home dot net
I've been running fine on CGI for a while now, jumping between 4.04, 4.07-dev, 4.05

When I tried to switch from 4.05 CGI to 4.05 4.05-Apache ... one of my files does not unserialize properly.  The error message is:

Warning: unserialize() failed at offset 487 of 2797 bytes in c:\program files\apache group\apache\htdocs\gt2\libraries\classes\module.class on line 189

If you guys know something about this, please let me know, as soon as possible.  In the mean time, I am going to make a script that saves a serialized object to disk.  I will save it to a file using CGI and then Apache modules.  Then, I will try to load em both using Apache and CGI modules... see what turns up.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-27 13:11 UTC] sniper@php.net
Please include a short example of both script and the class
you get this with.

 [2001-06-27 14:06 UTC] btanner at home dot net
Bingo.. got it down to a reasonable amount of code.

I'll provide the code here (its still 65 lines).  I have kept the "save" method, although it is not used in this example.  Reason being is that I am loading an object that I previously saved, so its possible that the save method is the offender.

Here you go.  I'll also reply to this message in php-dev (if the list ever starts working) -- with the datafile attached.

--Code starts--
<?
class Module_Variable{
var $Type;
var $Name;
var $Value;

	function Module_Variable($Name,$Value,$Type="S"){
		$this->Name=$Name;
		$this->Value=$Value;
		$this->Type=$Type;	
	}
} //end of module_variable class


class Module {
    var $Variables;  // Array of Configuration Variables for this Module
    var $Inclusions; // Array of Inclusions in case of newuser,deleteuser,etc,etc
    var $Path;       // Path from Root to get to this module
    var $Name;
    var $Loaded;     // Has this module been loaded, or not?
	
	
	function Module($Name,$Path){
		$this->Name=$Name;
		$this->Path=$Path;
		$this->Loaded=0;
		$this->Variables="";
	}
	
	function Save(){		
		$ModCode=serialize($this);			
		
		$FileLocation=__DATAPATH."mod_data/".$this->Name.".mod";
		
		$FilePointer=fopen($FileLocation,"w");
		$WriteCheck=fwrite($FilePointer,$ModCode);
	
		if(!$WriteCheck)
			die("Error writing output...");
		fclose($FilePointer);		
	}
	
	function Load(){
		
		$FileLocation=$this->Name.".mod";
		
		$FilePointer=@fopen($FileLocation,"r");
		if(!$FilePointer)
			$this->HandleError($FileLocation);
		$EncodedString=fread($FilePointer,filesize($FileLocation));
		fclose($FilePointer);
		
		$VarObject=unserialize($EncodedString);
		$this->Variables=$VarObject->Variables;
		
		$this->Loaded=1;
	}	   	
}//end the class

$MyModule=new Module("login","");
$MyModule->Load();

print("<hr><Br>Good so far");

?>
 [2001-06-27 14:32 UTC] btanner at home dot net
If it helps:

a)Script
b)Datafile

can be found in zip form at:

http://www.zaam.com/zend/bug11749.zip

Thanks for all your help on this guys.  
 [2001-06-28 11:29 UTC] btanner at home dot net
After changing all my reads and writes to forced binary reads and right, all is well with Win32 Apache module.

IMHO, this is still a bug.  If the behaviour is this for the module, it should also be the same for the CGI.

Why did this work?
 [2001-06-29 04:17 UTC] thies@php.net
binary mode only makes a difference when youstore 
carriage-returns in your file. i bet your "old" test did 
not have CR in the data.

i consider this problem "fixed"


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC