Talos Vulnerability Report

TALOS-2016-0193

OpenJPEG JPEG2000 mcc record Code Execution Vulnerability

September 29, 2016

CVE Number

CVE-2016-8332

Summary

An exploitable code execution vulnerability exists in the jpeg2000 image file format parser as implemented in the OpenJpeg library. A specially crafted jpeg2000 file can cause an out of bound heap write resulting in heap corruption leading to arbitrary code execution. For a successful attack, the target user needs to open a malicious jpeg2000 file. The jpeg2000 image file format is mostly used for embedding images inside PDF documents and the OpenJpeg library is used by a number of popular PDF renderers making PDF documents a likely attack vector.

Tested Versions

Product URLs

CVSSv3 Score

Details

The OpenJpeg library is a reference implementation of JPEG2000 standard and is used by many popular PDF renderers. Most notably Poppler, MuPDF and Pdfium.

Due to an error while parsing mcc records in the jpeg2000 file, out of bounds memory can be accessed resulting in an erroneous read and write of adjacent heap area memory. Careful manipulation of heap layout and can lead to further heap metadata process memory corruption ultimately leading to code execution under attacker control.

The vulnerability lies in opj_j2k_read_mcc_record function in src/lib/openjp2/j2k.c file which is responsible for parsing mcc records.

The first if statement is entered if the index was not found, then, if current number of records has reached a maximum of l_tcp->m_nb_max_mcc_records (which is 10 initially), maximum is increased and memory is reallocated to accommodate more records. At the end of the function, number of records is increased:

```
++l_tcp->m_nb_mcc_records;
return OPJ_TRUE;
```

The vulnerability in the above code lies in the improper increment of the number of records at the end of the function. If a malicious image is created, such that it has a number of mcc records with the same (zero) index, the counter in the for loop can never reach the value that would satisfy i == l_tcp->m_nb_mcc_records condition. If there are 10 or more such objects, l_tcp->m_nb_mcc_records will be increased to more than l_tcp->m_nb_max_mcc_records without actually reallocating the appropriate amount of memory. If then there is an mcc record with a different index in the image, the if condition inside the for loop won’t ever be true, which will lead to l_mcc_record pointer being increased out of bounds, causing an out of bounds read. Further on, this out of bounds pointer is retained and is used in a write operation when its index is being updated by a controlled value.

By varying the number of mcc records, an attacker can target a particular heap memory area and by abusing the same bug multiple times gain enough control over the process memory to get arbitrary code execution.