| From: | Noah Misch <noah(at)leadboat(dot)com> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Avoid overflow in Levenshtein distance calculations. |
| Date: | 2026-08-10 13:41:31 |
| Message-ID: | E1wtQFv-00000000yLU-2LWg@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)gmail(dot)com>
Reviewed-by: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Security: CVE-2026-15742
Backpatch-through: 14
Branch
------
REL_15_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/74916136fc6c9fcc5a94e1b53863703593009583
Author: Nathan Bossart <nathan(at)postgresql(dot)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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Noah Misch | 2026-08-10 13:41:32 | pgsql: psql: Don't do backquote expansion in \unrestrict. |
| Previous Message | Noah Misch | 2026-08-10 13:41:30 | pgsql: pgcrypto: Add option to revert to prior decryption behavior |