klaussilveira / SimpleSHM

SimpleSHM is a simple and small abstraction layer for shared memory manipulation using PHP. It makes use of the SHMOP functions, built into most PHP packages.
BSD 3-Clause "New" or "Revised" License
136 stars 46 forks source link

Reserved block size could be too small #1

Open gwyn opened 12 years ago

gwyn commented 12 years ago

Hello Klaus,

I believe there is a problem with this line: $size = mb_strlen($data, 'UTF-8');

It returns the number of UTF-8 characters in $data. As UTF-8 is a multi-byte encoding, this number can vary from the actual length in bytes. This means the string would not fit into the reserved shared memory block.

The following fix would return the number of bytes: $size = mb_strlen($data, '8bit');

Best regards, gwyn

abiusx commented 7 years ago

Yes I wanted to say the same thing. You need the number of bytes not characters. Also, only increase size if necessary. No need to shrink. Or put a threshold.