agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid overflow in Levenshtein distance calculations.
Date: Mon, 10 Aug 2026 13:41:23 +0000
Message-ID: <E1wtQFn-00000000y5L-00ry@gemulon.postgresql.org> (raw)
Avoid overflow in Levenshtein distance calculations.
levenshtein() and levenshtein_less_equal() let the caller specify
the insertion, deletion, and substitution costs, and
fuzzystrmatch's corresponding SQL functions accept any 32-bit
integer for each. Since the distances are calculated with 32-bit
arithmetic, large costs can cause overflows, thereby producing
nonsensical results. Certain inputs to levenshtein_less_equal()
can even cause out-of-bounds writes. To fix, use 64-bit arithmetic
instead, and error whenever the final result won't fit in the
returned 32-bit integer.
We may want to teach these functions to reject negative costs, too,
but that didn't seem appropriate for a security fix, and therefore
it is left as a future exercise.
Reported-by: Ben Morris in collaboration with Claude and Anthropic Research
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Security: CVE-2026-15742
Backpatch-through: 14
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/62c31b490d94b38a62869593524abca5f67c4c46
Author: Nathan Bossart <nathan@postgresql.org>
Modified Files
--------------
contrib/fuzzystrmatch/expected/fuzzystrmatch.out | 14 ++++
contrib/fuzzystrmatch/sql/fuzzystrmatch.sql | 3 +
src/backend/utils/adt/levenshtein.c | 89 ++++++++++++------------
src/backend/utils/adt/varlena.c | 14 ++++
4 files changed, 77 insertions(+), 43 deletions(-)
view thread (5+ messages) latest in thread
Message-ID: <E1wtQFn-00000000y5L-00ry@gemulon.postgresql.org>
Permalink: ../E1wtQFn-00000000y5L-00ry@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wtQFn-00000000y5L-00ry@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: noah@leadboat.com, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Avoid overflow in Levenshtein distance calculations.
In-Reply-To: <E1wtQFn-00000000y5L-00ry@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox