Project

General

Profile

Actions

Bug #1018

closed

JPEG decoder refuses some valid images containing unusual Huffman tables

Added by Marco Eichelberg over 3 years ago. Updated over 3 years ago.

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 <>


Files

lena.dcm (628 KB) lena.dcm DICOM image in lossless JPEG encoding that demonstrates the issue Marco Eichelberg, 2022-03-15 11:41
Actions #1

Updated by Marco Eichelberg over 3 years ago

Update: libjpeg is used in the pydicom library:
Actions #2

Updated by Marco Eichelberg over 3 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Closed by commit #deeda9adb.

Actions

Also available in: Atom PDF