Actions
Bug #1018
closedJPEG decoder refuses some valid images containing unusual Huffman tables
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Library and Apps
Target version:
-
Start date:
2022-03-15
Due date:
% Done:
100%
Estimated time:
Module:
dcmjpeg
Operating System:
Compiler:
Description
The Huffman decoder in dcmjpeg (in the files dcmjpeg/libijg[8|12|16]/jdhuff.c) checks the DC Huffman tables for validity. However, at lease one JPEG library (Thomas Richters's libjpeg, which is apparently used in the GDCM DICOM Toolkit) encodes Huffman tables that contain symbols that trigger an error message. According to the author of that library, these are default Huffman tables and the 'illegal' values are included because they are actually needed in some non-baseline JPEG processes, such as extended sequential mode. The problem can be fixed by disabling this arguably overly strict check:
/* Validate symbols as being reasonable. * For AC tables, we make no check, but accept all byte values 0..255. * For DC tables, we require the symbols to be in range 0..16. * (Tighter bounds could be applied depending on the data depth and mode, * but this is sufficient to ensure safe decoding.) */ if (isDC) { for (i = 0; i < numsymbols; i++) { int sym = htbl->huffval[i]; if (sym < 0 || sym > 16) ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); } }
Reported 2022-03-15 by Mathieu Malaterre <mathieu.malaterre@gmail.com>
Files
Actions