agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Avoid overflow in Levenshtein distance calculations.
5+ messages / 1 participants
[nested] [flat]

* pgsql: Avoid overflow in Levenshtein distance calculations.
@ 2026-08-10 13:41 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Noah Misch @ 2026-08-10 13:41 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/918683d12d849a514cd38056aab882322c74adb4
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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Avoid overflow in Levenshtein distance calculations.
@ 2026-08-10 13:41 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Noah Misch @ 2026-08-10 13:41 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Avoid overflow in Levenshtein distance calculations.
@ 2026-08-10 13:41 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Noah Misch @ 2026-08-10 13:41 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e88eb4e766381070f42e5b84e583a1d0288983f7
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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Avoid overflow in Levenshtein distance calculations.
@ 2026-08-10 13:41 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Noah Misch @ 2026-08-10 13:41 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c4d51b62748fd697e5ef4c1108dc77396ba39475
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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Avoid overflow in Levenshtein distance calculations.
@ 2026-08-10 13:41 Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Noah Misch @ 2026-08-10 13:41 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/61481aa0e4aa66c32a8826732f30d17d4c488d06
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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-08-10 13:41 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-10 13:41 pgsql: Avoid overflow in Levenshtein distance calculations. Noah Misch <noah@leadboat.com>
2026-08-10 13:41 pgsql: Avoid overflow in Levenshtein distance calculations. Noah Misch <noah@leadboat.com>
2026-08-10 13:41 pgsql: Avoid overflow in Levenshtein distance calculations. Noah Misch <noah@leadboat.com>
2026-08-10 13:41 pgsql: Avoid overflow in Levenshtein distance calculations. Noah Misch <noah@leadboat.com>
2026-08-10 13:41 pgsql: Avoid overflow in Levenshtein distance calculations. Noah Misch <noah@leadboat.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox