Protect against overflow of ltree.numlevel and lquery.numlevel.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 2618ac6c6535171f4993a38e3410955e1c2a2073
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2020-03-28T21:09:51Z
Releases: 10.13
Protect against overflow of ltree.numlevel and lquery.numlevel.

These uint16 fields could be overflowed by excessively long input,
producing strange results.  Complain for invalid input.

Likewise check for out-of-range values of the repeat counts in lquery.
(We don't try too hard on that one, notably not bothering to detect
if atoi's result has overflowed.)

Also detect length overflow in ltree_concat.

In passing, be more consistent about whether "syntax error" messages
include the type name.  Also, clarify the documentation about what
the size limit is.

This has been broken for a long time, so back-patch to all supported
branches.

Nikita Glukhov, reviewed by Benjie Gillam and Tomas Vondra

Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com

Files

PathChange+/−
contrib/ltree/expected/ltree.out modified +46 −0
contrib/ltree/ltree.h modified +2 −0
contrib/ltree/ltree_io.c modified +36 −18
contrib/ltree/ltree_op.c modified +8 −1
contrib/ltree/sql/ltree.sql modified +11 −0
doc/src/sgml/ltree.sgml modified +1 −2

Documentation touched

Discussion