Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0782050

Browse files
committed
Catch invalid typlens in a couple of places
Rearrange the logic in record_image_cmp() and record_image_eq() toerror out on unexpected typlens (either not supported there orcompletely invalid due to corruption). Barring corruption, this isnot possible today but it seems more future-proof and robust to fixthis.Reported-by: Peter Geoghegan <pg@bowt.ie>
1 parent88d03d7 commit0782050

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

‎src/backend/utils/adt/rowtypes.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,18 @@ record_image_cmp(FunctionCallInfo fcinfo)
14421442
}
14431443

14441444
/* Compare the pair of elements */
1445-
if (att1->attlen==-1)
1445+
if (att1->attbyval)
1446+
{
1447+
if (values1[i1]!=values2[i2])
1448+
cmpresult= (values1[i1]<values2[i2]) ?-1 :1;
1449+
}
1450+
elseif (att1->attlen>0)
1451+
{
1452+
cmpresult=memcmp(DatumGetPointer(values1[i1]),
1453+
DatumGetPointer(values2[i2]),
1454+
att1->attlen);
1455+
}
1456+
elseif (att1->attlen==-1)
14461457
{
14471458
Sizelen1,
14481459
len2;
@@ -1465,17 +1476,8 @@ record_image_cmp(FunctionCallInfo fcinfo)
14651476
if ((Pointer)arg2val!= (Pointer)values2[i2])
14661477
pfree(arg2val);
14671478
}
1468-
elseif (att1->attbyval)
1469-
{
1470-
if (values1[i1]!=values2[i2])
1471-
cmpresult= (values1[i1]<values2[i2]) ?-1 :1;
1472-
}
14731479
else
1474-
{
1475-
cmpresult=memcmp(DatumGetPointer(values1[i1]),
1476-
DatumGetPointer(values2[i2]),
1477-
att1->attlen);
1478-
}
1480+
elog(ERROR,"unexpected attlen: %d",att1->attlen);
14791481

14801482
if (cmpresult<0)
14811483
{
@@ -1671,7 +1673,17 @@ record_image_eq(PG_FUNCTION_ARGS)
16711673
}
16721674

16731675
/* Compare the pair of elements */
1674-
if (att1->attlen==-1)
1676+
if (att1->attbyval)
1677+
{
1678+
result= (values1[i1]==values2[i2]);
1679+
}
1680+
elseif (att1->attlen>0)
1681+
{
1682+
result= (memcmp(DatumGetPointer(values1[i1]),
1683+
DatumGetPointer(values2[i2]),
1684+
att1->attlen)==0);
1685+
}
1686+
elseif (att1->attlen==-1)
16751687
{
16761688
Sizelen1,
16771689
len2;
@@ -1700,16 +1712,9 @@ record_image_eq(PG_FUNCTION_ARGS)
17001712
pfree(arg2val);
17011713
}
17021714
}
1703-
elseif (att1->attbyval)
1704-
{
1705-
result= (values1[i1]==values2[i2]);
1706-
}
17071715
else
1708-
{
1709-
result= (memcmp(DatumGetPointer(values1[i1]),
1710-
DatumGetPointer(values2[i2]),
1711-
att1->attlen)==0);
1712-
}
1716+
elog(ERROR,"unexpected attlen: %d",att1->attlen);
1717+
17131718
if (!result)
17141719
break;
17151720
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp