Trying to add a "problematic" PNG into a pdf causes an unmanaged exception in our application because pdfKit doesn't give us any way to capture the exception.
The problem is in the asynchronous API internally used to decode PNGs. Look this code into png-node.js file:
As you can see, the "err" parameter in the callback is not treated properly and, in fact, the "fn" parameter doesn't expect to be informed about possible errors.
Trying to add a "problematic" PNG into a pdf causes an unmanaged exception in our application because pdfKit doesn't give us any way to capture the exception.
The problem is in the asynchronous API internally used to decode PNGs. Look this code into png-node.js file:
An internal
throw new Error("invalid filter..:")
is raised into the zlib.inflate callback causing NODE to capture it as an unmanaged exception.Wrapping call into a try { } catch { } structure, doesn't help (because Inflate is called asynchronously )
In summary, calling
image.decodePixels(function(data){...})
with problematic images can produce errors that are not "capturable" by the caller .Only a comment: png-node.js API is asynchronows but without "error" management... that's really a bad library for a server side NODE application
you can find pieces of code like this:
As you can see, the "err" parameter in the callback is not treated properly and, in fact, the "fn" parameter doesn't expect to be informed about possible errors.