devongovett/pdfkit — pull request #141 by mark-hahn (2013-07-04 18:53:09+00:00)
Title: critical bug fix for JPEG

Certain JPEG files are decoded improperly by pdfkit. Specifically the width and height are parsed incorrectly. See issue #138 for a problem description and a sample JPEG file which shows the problem.

I found the smoking-gun bug and have a fix here. A more detailed description of the problem follows.

jpeg.coffee has a list of SOF markers. They indicate the start of frames that include the width and height of the image. This list of SOF markers includes FFC4 which is actually a DHT, not an SOF. The DHT stands for "Define Huffman Table". Simply removing FFC4 from the SOF list fixes the problem.

The definition for the markers is described in the Syntax and Structure section of this wikipedia page: https://en.wikipedia.org/wiki/JPEG.