Introduction
On November 12, 2026, PostgreSQL shipped out-of-cycle minor releases for every supported branch from 14 upward. They fix an integer wraparound in in-memory tuple size calculations that lets a database user execute arbitrary code as the operating system account running the server. Any deployment that hands out database logins to applications, analysts, or tenants is exposed: an ordinary SQL account could become a route to code execution on the database host itself.
PostgreSQL, acting as CNA, scores CVE 2026 120139 at CVSS 3.1 8.8 (High) with the vector AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H. NVD displays that CNA score but has not yet provided its own assessment. We found no reliable source confirming exploitation in the wild or naming a threat actor. That status is unknown, not confirmed absent.
Technical information
Root cause
The weakness is classified as CWE 190, Integer Overflow or Wraparound. According to the commit message for 317b7bcab, in-memory tuple sizes were calculated in 64-bit sized variables and later assigned to 32-bit variables. That mismatch allowed the size value to wrap, and the commit message states the wraparound could be used to overwrite server memory with attacker-controlled contents. The advisory describes the end result as arbitrary code execution as the operating system user running the database, triggered via oversized tuple data.
The vulnerable pattern was plain, unchecked accumulation. In heap_compute_data_size, which sums the data size of every attribute in a tuple, each addition looked like this before the fix:
data_length += VARATT_CONVERTED_SHORT_SIZE(DatumGetPointer(val));
The patch touches several other sites that summed sizes the same unchecked way:
heap_compute_data_size()in the heap codetts_virtual_materialize()in the executor (execTuples.c)expand_tuple()inheaptuple.c, when values for missing attributes are added innocachegetattr(), where the offset variable was anintmultirange_size_estimate(), which sums range bound sizesarray_agg_array_combine()
The existing att_addlength_pointer macro, which adds an attribute length to the current offset, also performed no overflow check.
Attack flow
Based on the advisory, the CVSS vector, and the commit message, exploitation proceeds along these lines:
- The attacker holds a database login. The vector rates privileges required as Low. The record does not describe an unauthenticated attacker gaining code execution simply by reaching the PostgreSQL port.
- Over a network connection (AV:N), with no user interaction required (UI:N), the attacker causes the server to process oversized tuple data.
- While computing the in-memory size of that tuple, the server sums attribute sizes in a 64-bit variable that is later assigned to a 32-bit variable, and the value wraps.
- The wrapped size is used for memory handling, which lets the attacker overwrite server memory with attacker-controlled contents.
- The attacker achieves arbitrary code execution as the operating system user running PostgreSQL. Confidentiality, integrity, and availability impacts are each rated High, with scope Unchanged.
The public material does not include a payload, a detailed trigger sequence, or a proof of concept, and the advisory does not state that the code runs as an operating system administrator.
Patch information
The 18.7 release notes list the fix as "Harden more memory size calculations against integer overflow" credited to Álvaro Herrera, and link two commits that Noah Misch committed on November 9, 2026. Both carry a Security trailer naming this CVE and are backpatched through branch 14.
| Commit | Role |
|---|---|
317b7bcab | The fix for tuple size wraparound in the heap, executor, array and multirange code |
f1b226dee | Extra hardening of TOAST, decompression and array_cat. The commit message says it "isn't closing any specific security bug" |
The fix has two parts. It uses overflow-aware addition (pg_add_size_overflow) instead of plain +=, and when sizes are summed in a loop, it checks after every step that the running total is still within the 1 GB palloc limit (AllocSizeIsValid). Oversized values are rejected before they can wrap.
heap_compute_data_size now checks its running total
Each unchecked addition is replaced with a checked form:
ovfl = pg_add_size_overflow(data_length, VARATT_CONVERTED_SHORT_SIZE(DatumGetPointer(val)), &data_length);
After the loop, the function raises an error if the total overflowed or exceeds the allocation limit:
if (ovfl || (!allow_huge && !AllocSizeIsValid(data_length))) ereport(ERROR, errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("tuple is too big"));
The old function name is kept as a wrapper passing allow_huge = false. A new heap_compute_data_size_ext(..., bool allow_huge) covers the one legitimate case for sizes above 1 GB: heap_toast_insert_or_update, which must measure a row before compressing it or moving it out of line. Its four while (... > maxDataLen) loops now call the _ext variant with allow_huge = true. In that mode the 1 GB check is skipped but overflow detection stays on, because, as the patch comment notes, the AllocSizeIsValid() test alone cannot be trusted on 32-bit platforms.
A new overflow-checking helper in tupmacs.h
Alongside the unchecked att_addlength_pointer macro, the patch adds a checked inline version. Its signature and core check:
static inline Size att_addlength_pointer_overflow(Size cur_offset, int16 attlen, const void *attptr, bool *overflow) { /* ... compute add for the attribute kind ... */ *overflow = pg_add_size_overflow(cur_offset, add, &cur_offset); return cur_offset; }
It handles all three attribute kinds: fixed-width, varlena, and cstring. A wrapper macro, att_addlength_datum_overflow, makes it usable with Datums, and that macro replaces the old att_addlength_datum call inside heap_compute_data_size.
The 1 GB check at other size-summing sites
tts_virtual_materialize(): after each attribute size is added, the total is checked withAllocSizeIsValid(sz). Failure raisestuple is too big.expand_tuple(): the same check runs after values for missing attributes are added in.nocachegetattr(): the offset variable is widened frominttoSize, andAssert(AllocSizeIsValid(tup->t_len))is added.multirange_size_estimate(): the loop summing range bound sizes raisesmultirange is too bigonce the total passes the limit.array_agg_array_combine(): the existingpg_add_s32_overflowchecks now also fail if!AllocSizeIsValid(reqsize).
Companion hardening in f1b226dee
table_relation_fetch_toast_slice()rejects negative slice parameters and a slice length larger thanattrsizeminussliceoffset.pglz_decompress_datum_slice()andlz4_decompress_datum_slice()checkAllocSizeIsValid(slicelength)before callingpalloc(slicelength + VARHDRSZ).lz4_compress_datum()validates the result ofLZ4_compressBound(), in case a future or malicious LZ4 library returns a bound large enough to wrap the header addition.detoast_external_attr()gains a compile-timeStaticAssertExpr(VARLENA_EXTSIZE_MASK <= MaxAllocSize, ...). The assumption that a stored TOAST size never exceeds whatpalloccan allocate becomes a build-time guarantee.array_cat()computes the combined data size withpg_add_s32_overflowand raisesresult array is too bigon overflow or if the size is invalid.
Behaviour after patching
Inputs that previously wrapped the size counter now stop the query cleanly with an ERRCODE_PROGRAM_LIMIT_EXCEEDED error such as tuple is too big, before any undersized buffer is allocated or written. Normal-sized rows are unaffected, and TOAST can still measure rows larger than 1 GB before compressing them.
Because these are minor releases, PostgreSQL guidance is to stop the server and replace the binaries. No dump and reload or pg_upgrade is needed. Update releases are cumulative, and installations that skipped one or more update releases should check the release notes for any additional post-update steps. The advisory does not describe a separate workaround.
Affected systems and versions
All PostgreSQL server releases earlier than the following fixed minor versions are affected:
| PostgreSQL branch | Affected releases | Fixed release |
|---|---|---|
| 18 | Earlier than 18.7 | 18.7 |
| 17 | Earlier than 17.12 | 17.12 |
| 16 | Earlier than 16.16 | 16.16 |
| 15 | Earlier than 15.20 | 15.20 |
| 14 | Earlier than 14.25 | 14.25 |
Exploitation requires a database user account (PR:L). NVD lists the same version thresholds and identifies PostgreSQL as the CNA.
References
- NVD entry for CVE 2026 120139
- CVE Program record for CVE 2026 120139
- PostgreSQL security advisory for CVE 2026 120139
- PostgreSQL 18.7, 17.12, 16.16, 15.20, 14.25, and 19 RC 2 release announcement
- PostgreSQL 18.7 release notes
- Commit 317b7bcab: tuple size wraparound fix
- Commit f1b226dee: companion hardening
- PostgreSQL security information and policy
- PostgreSQL versioning policy
- About PostgreSQL
- Stack Overflow 2026 Developer Survey: databases
- CISA Known Exploited Vulnerabilities catalog



