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

Commit6923d69

Browse files
committed
Protect GIST logic that assumes penalty values can't be negative.
Apparently sane-looking penalty code might return small negative values,for example because of roundoff error. This will confuse places likegistchoose(). Prevent problems by clamping negative penalty values tozero. (Just to be really sure, I also made it force NaNs to zero.)Back-patch to all supported branches.Alexander Korotkov
1 parentba4cacf commit6923d69

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

‎doc/src/sgml/gist.sgml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ my_decompress(PG_FUNCTION_ARGS)
378378
Returns a value indicating the <quote>cost</quote> of inserting the new
379379
entry into a particular branch of the tree. Items will be inserted
380380
down the path of least <function>penalty</function> in the tree.
381+
Values returned by <function>penalty</function> should be non-negative.
382+
If a negative value is returned, it will be treated as zero.
381383
</para>
382384

383385
<para>

‎src/backend/access/gist/gistutil.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
#include"postgres.h"
1515

16+
#include<math.h>
17+
1618
#include"access/gist_private.h"
1719
#include"access/reloptions.h"
1820
#include"storage/freespace.h"
@@ -526,16 +528,21 @@ gistpenalty(GISTSTATE *giststate, int attno,
526528

527529
if (giststate->penaltyFn[attno].fn_strict== FALSE||
528530
(isNullOrig== FALSE&&isNullAdd== FALSE))
531+
{
529532
FunctionCall3Coll(&giststate->penaltyFn[attno],
530533
giststate->supportCollation[attno],
531534
PointerGetDatum(orig),
532535
PointerGetDatum(add),
533536
PointerGetDatum(&penalty));
537+
/* disallow negative or NaN penalty */
538+
if (isnan(penalty)||penalty<0.0)
539+
penalty=0.0;
540+
}
534541
elseif (isNullOrig&&isNullAdd)
535542
penalty=0.0;
536543
else
537-
penalty=1e10;/* try to preventto mix null and non-null
538-
*value */
544+
penalty=1e10;/* try to preventmixing null and non-null
545+
*values */
539546

540547
returnpenalty;
541548
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp