Automated Threat Modeling

Overview of CVE 2026 120139: PostgreSQL Tuple Size Integer Wraparound Leading to Code Execution

CVE 2026 120139 is an integer wraparound in PostgreSQL's in-memory tuple size calculations that lets a database user execute code as the operating system account running the database. This post covers the root cause, the two fix commits, and the fixed minor releases.

CVE Analysis

7 min read

Gaurav Sarraf
Gaurav Sarraf

2026-11-12

Overview of CVE 2026 120139: PostgreSQL Tuple Size Integer Wraparound Leading to Code Execution

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 code
  • tts_virtual_materialize() in the executor (execTuples.c)
  • expand_tuple() in heaptuple.c, when values for missing attributes are added in
  • nocachegetattr(), where the offset variable was an int
  • multirange_size_estimate(), which sums range bound sizes
  • array_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:

  1. 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.
  2. Over a network connection (AV:N), with no user interaction required (UI:N), the attacker causes the server to process oversized tuple data.
  3. 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.
  4. The wrapped size is used for memory handling, which lets the attacker overwrite server memory with attacker-controlled contents.
  5. 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.

CommitRole
317b7bcabThe fix for tuple size wraparound in the heap, executor, array and multirange code
f1b226deeExtra 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 with AllocSizeIsValid(sz). Failure raises tuple is too big.
  • expand_tuple(): the same check runs after values for missing attributes are added in.
  • nocachegetattr(): the offset variable is widened from int to Size, and Assert(AllocSizeIsValid(tup->t_len)) is added.
  • multirange_size_estimate(): the loop summing range bound sizes raises multirange is too big once the total passes the limit.
  • array_agg_array_combine(): the existing pg_add_s32_overflow checks now also fail if !AllocSizeIsValid(reqsize).

Companion hardening in f1b226dee

  • table_relation_fetch_toast_slice() rejects negative slice parameters and a slice length larger than attrsize minus sliceoffset.
  • pglz_decompress_datum_slice() and lz4_decompress_datum_slice() check AllocSizeIsValid(slicelength) before calling palloc(slicelength + VARHDRSZ).
  • lz4_compress_datum() validates the result of LZ4_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-time StaticAssertExpr(VARLENA_EXTSIZE_MASK <= MaxAllocSize, ...). The assumption that a stored TOAST size never exceeds what palloc can allocate becomes a build-time guarantee.
  • array_cat() computes the combined data size with pg_add_s32_overflow and raises result array is too big on 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 branchAffected releasesFixed release
18Earlier than 18.718.7
17Earlier than 17.1217.12
16Earlier than 16.1616.16
15Earlier than 15.2015.20
14Earlier than 14.2514.25

Exploitation requires a database user account (PR:L). NVD lists the same version thresholds and identifies PostgreSQL as the CNA.

References

Detect & fix
what others miss

Works with
  • GitHub
  • GitLab
  • Bitbucket
  • Azure DevOps Services
  • Gerrit
  • CVS
  • Jira
  • Linear
  • Slack
  • Security Compass
Explore integrations
Security magnifying glass visualization