VYPR
Unrated severityNVD Advisory· Published Jan 25, 2021· Updated Aug 4, 2024

CVE-2020-27814

CVE-2020-27814

Description

A heap-buffer-overflow in OpenJPEG 2.3.1's mqc.c can crash the application or allow arbitrary code execution when processing crafted PNG files.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

A heap-buffer-overflow in OpenJPEG 2.3.1's mqc.c can crash the application or allow arbitrary code execution when processing crafted PNG files.

Vulnerability

A heap-buffer overflow vulnerability exists in the opj_mqc_byteout function in lib/openjp2/mqc.c of OpenJPEG version 2.3.1 and potentially earlier versions [1][2]. The flaw occurs during the encoding of a PNG image into a JPEG 2000 stream, triggered via the opj_compress utility with the -M 3 flag. The overflow is a write of size 1 at an address 0 bytes to the right of a heap buffer, as reported by AddressSanitizer [1]. The vulnerable code path involves the MQ (Mellin–Quisquater) coder used in the JPEG 2000 compression process.

Exploitation

An attacker can exploit this vulnerability by supplying a specially crafted PNG file to the opj_compress tool (or any application using the OpenJPEG library to encode images). No authentication or special privileges are required; the attacker only needs the ability to deliver the malicious file to the victim. The exploitation sequence is: the victim runs opj_compress -i malicious.png -o output.j2k -M 3, which triggers the heap-buffer overflow in opj_mqc_byteout during the tile encoding phase [1]. The error was discovered using a fuzzer with AddressSanitizer [2].

Impact

Successful exploitation could lead to an application crash (denial of service) or, in some cases, arbitrary code execution with the privileges of the user running the application [1][2]. The vulnerability allows an out-of-bounds write, which may be leveraged for remote code execution if the attacker can control the overflow data [2].

Mitigation

The vulnerability is fixed in OpenJPEG version 2.4.0 [3]. Users should upgrade to this version or later. For distributions such as Gentoo, the update is available as >=media-libs/openjpeg-2.4.0:2 [3]. No known workaround exists for unpatched versions; users relying on OpenJPEG for PNG-to-JPEG2000 encoding should apply the patch immediately [3]. The CVE is not listed on the CISA Known Exploited Vulnerabilities (KEV) catalog as of this writing.

AI Insight generated on May 26, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected products

29

Patches

0

No patches discovered yet.

Vulnerability mechanics

Root cause

"Insufficient buffer allocation in `opj_tcd_code_block_enc_allocate_data` (7 bytes) leads to a heap-buffer-overflow when `opj_mqc_byteout` writes one byte past the end during MQ-coder flush."

Attack vector

An attacker provides a crafted PNG image to `opj_compress` (e.g., `opj_compress -i ./sample.png -o ./out.j2k -M 3`). The PNG decoder produces a code-block whose compressed data requires more than 7 bytes, but the encoder allocates only 7 bytes for the output buffer. During MQ-coder flush, `opj_mqc_byteout` writes a byte at offset 7 (one past the allocation), causing a heap-buffer-overflow. This can crash the application or, under the right heap layout, lead to arbitrary code execution.

Affected code

The heap-buffer-overflow occurs in `opj_mqc_byteout` at `lib/openjp2/mqc.c:505` during JPEG 2000 encoding. The allocation happens in `opj_tcd_code_block_enc_allocate_data` at `lib/openjp2/tcd.c:1256`, where only 7 bytes are allocated for the code-block data buffer. The overflow is triggered when `opj_mqc_flush` (mqc.c:218) writes one byte past the end of this undersized buffer.

What the fix does

The advisory does not include a patch diff. The issue report [ref_id=1] identifies that `opj_tcd_code_block_enc_allocate_data` allocates only 7 bytes for the code-block data buffer, but the MQ-coder flush routine (`opj_mqc_flush` / `opj_mqc_byteout`) writes beyond that limit. A proper fix would ensure the allocation size accounts for the actual maximum compressed output of the code-block, or add bounds checking in the MQ-coder write path to prevent writing past the allocated region.

Preconditions

  • inputThe attacker must supply a crafted PNG file that, when encoded to JPEG 2000, causes the code-block compressed data to exceed the 7-byte allocation.
  • configThe victim must run `opj_compress` (or any application using openjpeg2) with the malicious PNG as input.

Generated on May 31, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

6

News mentions

0

No linked articles in our index yet.