forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5b7b382
committed
Fix datalen calculation in tsvectorrecv().
After receiving position data for a lexeme, tsvectorrecv()advanced its "datalen" value by (npos+1)*sizeof(WordEntry)where the correct calculation is (npos+1)*sizeof(WordEntryPos).This accidentally failed to render the constructed tsvectorinvalid, but it did result in leaving some wasted spaceapproximately equal to the space consumed by the position data.That could have several bad effects:* Disk space is wasted if the received tsvector is stored into a table as-is.* A legal tsvector could get rejected with "maximum total lexeme length exceeded" if the extra space pushes it over the MAXSTRPOS limit.* In edge cases, the finished tsvector could be assigned a length larger than the allocated size of its palloc chunk, conceivably leading to SIGSEGV when the tsvector gets copied somewhere else. The odds of a field failure of this sort seem low, though valgrind testing could probably have found this.While we're here, let's express the calculation as"sizeof(uint16) + npos * sizeof(WordEntryPos)" to avoid the typepun implicit in the "npos + 1" formulation. It's not wronggiven that WordEntryPos had better be 2 bytes to avoid paddingproblems, but it seems clearer this way.Report and patch by Denis Erokhin. Back-patch to all supportedversions.Discussion:https://postgr.es/m/009801d9f2d9$f29730c0$d7c59240$@datagile.ru1 parentd8a0993 commit5b7b382
1 file changed
+2
-2
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
498 | 498 |
| |
499 | 499 |
| |
500 | 500 |
| |
501 |
| - | |
| 501 | + | |
502 | 502 |
| |
503 | 503 |
| |
504 | 504 |
| |
| |||
544 | 544 |
| |
545 | 545 |
| |
546 | 546 |
| |
547 |
| - | |
| 547 | + | |
548 | 548 |
| |
549 | 549 |
| |
550 | 550 |
| |
|
0 commit comments
Comments
(0)