wasmerio / wasmer-php

🐘🕸️ WebAssembly runtime for PHP
https://wasmerio.github.io/wasmer-php/wasm/
MIT License
1k stars 42 forks source link

fix(example) Account for null in allocation size. #100

Closed chinoto closed 4 years ago

chinoto commented 4 years ago

The potential issue won't be seen in the greet example, but could cause issues for those who just copy and paste the code. Perhaps there should be a comment explaining the +1?

Example of issue: Assume two allocations A and B next to each other in memory, where A doesn't account for the null in its size. If A is written first, then B, attempting to read A will result in a concatenation of the two. If B is written first, attempting to read B will result in an empty string.

chinoto commented 4 years ago

While looking through my Javascript port of greet.php I noticed I forgot to include the capacity argument in deallocate (surprisingly caused no errors) and checked the php version, finding that it also didn't account for the null terminator when deallocating.

Hywan commented 4 years ago

Thanks!