devongovett/png.js — pull request #9 by acruikshank (2012-11-19 21:42:13+00:00)
Title: Avoid infinite loop when parsing corrupt files.

Our node server has been crashing when we try to embed certain PNGs into PDFs with PDFKit. It turns out that the files were corrupt, but we're not keen to have the server go into an infinite loop just because someone uploaded a broken PNG. This patch checks to see if we're reading past the end of the data and, if so, throws and exception.

I've added a broken image to the samples. I didn't want to add a test framework, but running the following line in node from the project root is sufficient to see the difference in behavior:

```javascript
require('./').load('images/broken.png')
```