port upstream fix for local buffer overflow

r1425

Fix Huffman local buffer overrun discovered by Debian developers when
attempting to transform a junk image using ImageMagick:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=768369
Merge pull request #136 from tony2001/master

port upstream fix for local buffer overflow