Correctly limit bounds in PutImageData to prevent segment fault.
Merge pull request #383 from peerlibrary/bounds-checking

Correctly limit bounds in PutImageData to prevent segment fault