foliojs / png.js

A (animated) PNG decoder in JavaScript for the HTML5 canvas element and Node.js
http://devongovett.github.com/png.js
MIT License
489 stars 92 forks source link

Avoid infinite loop when parsing corrupt files. #9

Closed acruikshank closed 11 years ago

acruikshank commented 11 years ago

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:

require('./').load('images/broken.png')
devongovett commented 11 years ago

Merged. Thank you!