0

I am just developing my website, but I got an error

"Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes) in...".

The odd thing is that it works fine and my memory usage is about 500,000 right up until a single line in my code:

 echo'<script>alert("'."X-".memory_get_usage(true).'");</script>';
 $queryX = "SELECT `data`,`image`,`date` FROM messages WHERE toX = ? or fromX = ?";
 echo'<script>alert("'."X2-".memory_get_usage(true).'");</script>';
 $stmtX = $connection->prepare($queryX);
 echo'<script>alert("'."X3-".memory_get_usage(true).'");</script>';
 $stmtX->bind_param('ss',$idlistX[$i],$idlistX[$i]);
 echo'<script>alert("'."X4-".memory_get_usage(true).'");</script>';
 $stmtX->bind_result($dataT,$imageT,$dateT);

I have those alerts in to track it. Does anyone know how that last line is causing trouble?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
gareth power
  • 209
  • 2
  • 4
  • 12

1 Answers1

2

Do you happen to have a blob column?

4294967296 shows that you're trying to allocated memory, coincidently or not, that's the max length of a blob column.

It may as well but a bug, and not a leak, and it could come from the bind statements.

If you do have a blob column, try casting it to varchar in your select statement.

Andrei
  • 3,434
  • 5
  • 21
  • 44
  • Yes, The image one is a blob, but empty for now. How do I fix that then? – gareth power Jul 29 '16 at 14:04
  • 1
    Firstly, don't store images in the database as blobs. Store the path TO the image in the database and store the image itself on the harddrive. That should fix your problem. – Andrei Jul 29 '16 at 14:06
  • I know, but these are images users send to each other so I want them private – gareth power Jul 29 '16 at 14:15
  • Storing them in the database or storing them on the harddrive won't make much difference regarding privacy. Arguably you could say that they're more secure on the harddrive, since we're assuming here that one could easier get access to the database than the OS. And since he's got access to the OS, some images will be the least of your worries. – Andrei Jul 29 '16 at 14:19
  • Wait, (Thanks for the help btw) I dont understand, how would a user who is not meant to have direct access to the db , be able to access it here (I want a scure db)? And how would I change the blob to prevent this error anyway? – gareth power Jul 29 '16 at 14:21
  • A user could potentially get access to the database, but that is way beyond the scope of this question and quite frankly I'm not exactly qualified to answer that question in good manner. As for changing the blob, you can change it into varchar(50) - should be long enough - but you'll have to refactor some code to, in order to store only the image path and not the image itself. – Andrei Jul 29 '16 at 14:25
  • Oh okay. Thanks again for your help – gareth power Jul 29 '16 at 15:20
  • There are some reasons speaking **pro** storing images in databases rather than in the filesystem, for example that malicious code uploaded via an image cannot be executed. – syck Jul 29 '16 at 16:37
  • @syck True, I mean you could [store Hamlet in a image](https://www.reddit.com/r/PHP/comments/4socmz/storing_shakespeares_hamlet_invisibly_inside_an/) and [steganography](https://en.wikipedia.org/wiki/Steganography) is quite popular these days. – Andrei Jul 29 '16 at 17:10