Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.0b5

Bug #19136 Infinite Recurcsion makes result object unuseable
Submitted: 2011-12-15 01:19 UTC
From: pizzard Assigned: danielc
Status: Closed Package: MDB2 (version 2.4.1)
PHP Version: 5.3.7 OS: Debian Squeeze
Roadmaps: 2.5.0b4    

 [2011-12-15 01:19 UTC] pizzard (Martin Beeger)
Description: ------------ I spent 6 hours on this issue and also found a fix for it. I an using MDB2 with pgsql and tried to just execute a simple query on my database. But for any query, i get a Buffered result object. But acessing some method of it (like numRows() , gives me an MDB2_Error. Investigating the result object leads to the following Problem: The object contains a reference to it at $this->result instead of the ressource handle. This leads to an infinite recursion and an error. The reason for this is inside the Method mdb2->_wrapResult() of common driver. At line ~2570 there is $result = new $class_name($this, $result, $limit, $offset); Because in MDB2_Result_Common constuctor it says: $this->result =& $result; this assignment crashes all. A new object is created, and saved in $result, but this contanis a reference to result inside at $this->result now. So $this->result is also modified from psql resource (which it should be) to a pointer (reference) on the object itself. Fix: Add a $temp = $result; before this line and change it to: $result = new $class_name($this, $temp, $limit, $offset); Now because temp is copy of the ressource handler, it stays linked to $this->result and all is fine. Test script: --------------- //you got a valid MDB2 handle in $mdb2 $res =& $mdb2->query("SELECT 1;"); echo (int)$res->numRows(); Expected result: ---------------- 1 Actual result: -------------- Warning: pg_num_rows() expects parameter 1 to be resource, object given in my/path/MDB2/Driver/pgsql.php on line 1293 Notice: Object of class MDB2_Error could not be converted to int in my/path/login.php on line xx 0


 [2011-12-15 18:46 UTC] pizzard (Martin Beeger)
-Summary: Infinite Resurcsion makes result object unuseable +Summary: Infinite Recurcsion makes result object unuseable
 [2011-12-20 05:57 UTC] danielc (Daniel Convissor)
-Status: Open +Status: Closed -Assigned To: +Assigned To: danielc
Looking at the code in, I see that MDB2_Result_Common::__construct() no longer assigns by reference. Please reopen the bug if the problem still appears in the next release.
 [2011-12-20 18:16 UTC] pizzard (Martin Beeger)
-Status: Closed +Status: Critical -Package Version: 2.5.0b3 +Package Version: 2.4.1
Yeah, i checked that, and it is truly fixed in svn, but the actual stable release still contains this bug which e.g. makes it completely unuseable with the postgresql driver (and all other drivers which doesd not implment a seperate result constructor, which some do). Should be also hotfixed in this release or it should be marked as completely unuseable somewere.
 [2011-12-20 19:29 UTC] danielc (Daniel Convissor)
-Status: Critical +Status: Closed
We don't do hotfixes for earlier releases. It's fixed in the next active release.