For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > January 2006 > #35759 [Asn->Csd]: mysqli_stmt_bind_result() makes huge allocation when column emp









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #35759 [Asn->Csd]: mysqli_stmt_bind_result() makes huge allocation when column emp
andrey@php.net

2006-01-09, 8:02 pm

ID: 35759
Updated by: andrey@php.net
Reported By: squasar at eternalviper dot net
-Status: Assigned
+Status: Closed
Bug Type: Documentation problem
Operating System: *
PHP Version: 5.1.1
Assigned To: andrey
New Comment:

Should be fixed by now.
Thanks for reporting!


Previous Comments:
------------------------------------------------------------------------

[2005-12-21 09:16:48] sniper@php.net

This sounds more like documentation issue than a real bug, but I let
Georg decide.

------------------------------------------------------------------------

[2005-12-21 07:41:55] squasar at eternalviper dot net

Description:
------------
If a MEDIUMBLOB column has an empty value (length of zero),
mysqli_stmt_bind_result() attempts to allocate a buffer of 16M
for it. The offending code is in mysqli_api.c, line 332:

if (stmt->stmt->fields[ofs].max_length == 0) {

This will be true if the column is empty as well as in the
case where the user has not called store_result(). The result
is the code using the value of length instead of max_length,
which is 16M for a mediumblob.

Reproduce code:
---------------
Assume there exists a table:
CREATE TABLE a_table ( some_blob MEDIUMBLOB NOT NULL );

<?php

$m = new mysqli( MY_DB_HOST, MY_DB_USER, MY_DB_PASS );
$s = new mysqli_stmt( $m, "SELECT some_blob FROM a_table WHERE
some_blob='' LIMIT 1" );
$s->execute();
$s->store_result();
print_r( $s->result_metadata()->fetch_fields() );
$s->bind_result( $data );
$s->fetch();
print_r( $data );

?>


Expected result:
----------------
Array
(
[0] => stdClass Object
(
[name] => some_blob
[orgname] => some_blob
[table] => a_table
[orgtable] => a_table
[def] =>
[max_length] => 0
[length] => 0
[charsetnr] => 63
[flags] => 144
[type] => 252
[decimals] => 0
)

)


Actual result:
--------------
Array
(
[0] => stdClass Object
(
[name] => some_blob
[orgname] => some_blob
[table] => a_table
[orgtable] => a_table
[def] =>
[max_length] => 0
[length] => 16777215
[charsetnr] => 63
[flags] => 144
[type] => 252
[decimals] => 0
)

)

Fatal error: Allowed memory size of 8388608 bytes exhausted
(tried to allocate 16777216 bytes) in test.php on line 8



------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=35759&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com