mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Fix crash when using COLLATE in partition bound expressions
Attempting to use a COLLATE clause with a type that it not collatable in
a partition bound expression could crash the server. This commit fixes
the code by adding more checks similar to what is done when computing
index or partition attributes by making sure that there is a collation
iff the type is collatable.
Backpatch down to 12, as 7c079d7
introduced this problem.
Reported-by: Alexander Lakhin
Author: Dmitry Dolgov
Discussion: https://postgr.es/m/16325-809194cf742313ab@postgresql.org
Backpatch-through: 12
This commit is contained in:
@ -4081,6 +4081,30 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
|
||||
{
|
||||
Oid exprCollOid = exprCollation(value);
|
||||
|
||||
/*
|
||||
* Check we have a collation iff it is a collatable type. The only
|
||||
* expected failures here are (1) COLLATE applied to a noncollatable
|
||||
* type, or (2) partition bound expression had an unresolved
|
||||
* collation. But we might as well code this to be a complete
|
||||
* consistency check.
|
||||
*/
|
||||
if (type_is_collatable(colType))
|
||||
{
|
||||
if (!OidIsValid(exprCollOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDETERMINATE_COLLATION),
|
||||
errmsg("could not determine which collation to use for partition bound expression"),
|
||||
errhint("Use the COLLATE clause to set the collation explicitly.")));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OidIsValid(exprCollOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("collations are not supported by type %s",
|
||||
format_type_be(colType))));
|
||||
}
|
||||
|
||||
if (OidIsValid(exprCollOid) &&
|
||||
exprCollOid != DEFAULT_COLLATION_OID &&
|
||||
exprCollOid != partCollation)
|
||||
|
Reference in New Issue
Block a user