1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Catch invalid typlens in a couple of places

Rearrange the logic in record_image_cmp() and datum_image_eq() to
error out on unexpected typlens (either not supported there or
completely invalid due to corruption).  Barring corruption, this is
not possible today but it seems more future-proof and robust to fix
this.

Reported-by: Peter Geoghegan <pg@bowt.ie>
This commit is contained in:
Peter Eisentraut
2019-11-04 08:30:00 +01:00
parent db27b60f07
commit 8557a6f10c
2 changed files with 25 additions and 21 deletions

View File

@@ -265,7 +265,17 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
{
bool result = true;
if (typLen == -1)
if (typByVal)
{
result = (value1 == value2);
}
else if (typLen > 0)
{
result = (memcmp(DatumGetPointer(value1),
DatumGetPointer(value2),
typLen) == 0);
}
else if (typLen == -1)
{
Size len1,
len2;
@@ -294,16 +304,8 @@ datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
pfree(arg2val);
}
}
else if (typByVal)
{
result = (value1 == value2);
}
else
{
result = (memcmp(DatumGetPointer(value1),
DatumGetPointer(value2),
typLen) == 0);
}
elog(ERROR, "unexpected typLen: %d", typLen);
return result;
}