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

Commit0347470

Browse files
committed
Avoid divide-by-zero in regex_selectivity() with long fixed prefix.
Given a regex pattern with a very long fixed prefix (approaching 500characters), the result of pow(FIXED_CHAR_SEL, fixed_prefix_len) canunderflow to zero. Typically the preceding selectivity calculationwould have underflowed as well, so that we compute 0/0 and get NaN.In released branches this leads to an assertion failure later on.That doesn't happen in HEAD, for reasons I've not explored yet,but it's surely still a bug.To fix, just skip the division when the pow() result is zero, sothat we'll (most likely) return a zero selectivity estimate. Inthe edge cases where "sel" didn't yet underflow, perhaps thisisn't desirable, but I'm not sure that the case is worth spendinga lot of effort on. The results of regex_selectivity_sub() arebarely worth the electrons they're written on anyway :-(Per report from Alexander Lakhin. Back-patch to all supported versions.Discussion:https://postgr.es/m/6de0a0c3-ada9-cd0c-3e4e-2fa9964b41e3@gmail.com
1 parent5b2945e commit0347470

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,18 @@ regex_selectivity(const char *patt, int pattlen, bool case_insensitive,
14241424
sel *=FULL_WILDCARD_SEL;
14251425
}
14261426

1427-
/* If there's a fixed prefix, discount its selectivity */
1427+
/*
1428+
* If there's a fixed prefix, discount its selectivity. We have to be
1429+
* careful here since a very long prefix could result in pow's result
1430+
* underflowing to zero (in which case "sel" probably has as well).
1431+
*/
14281432
if (fixed_prefix_len>0)
1429-
sel /=pow(FIXED_CHAR_SEL,fixed_prefix_len);
1433+
{
1434+
doubleprefixsel=pow(FIXED_CHAR_SEL,fixed_prefix_len);
1435+
1436+
if (prefixsel>0.0)
1437+
sel /=prefixsel;
1438+
}
14301439

14311440
/* Make sure result stays in range */
14321441
CLAMP_PROBABILITY(sel);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp