postgresql/src/backend
Tom Lane 5b7b382464 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 tsvector
invalid, but it did result in leaving some wasted space
approximately 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 type
pun implicit in the "npos + 1" formulation.  It's not wrong
given that WordEntryPos had better be 2 bytes to avoid padding
problems, but it seems clearer this way.

Report and patch by Denis Erokhin.  Back-patch to all supported
versions.

Discussion: https://postgr.es/m/009801d9f2d9$f29730c0$d7c59240$@datagile.ru
2023-10-01 13:16:47 -04:00
..
access Fix btmarkpos/btrestrpos array key wraparound bug. 2023-09-28 16:29:37 -07:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Move PG_TEMP_FILE* macros to file_utils.h. 2023-09-05 17:02:06 -07:00
bootstrap Make error messages about WAL segment size more consistent 2023-08-28 15:17:04 +02:00
catalog Fix checking of index expressions in CompareIndexInfo(). 2023-09-28 14:05:25 -04:00
commands In COPY FROM, fail cleanly when unsupported encoding conversion is needed. 2023-10-01 12:09:26 -04:00
executor Fix EvalPlanQual rechecking during MERGE. 2023-09-30 10:52:21 +01:00
foreign Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
jit llvmjit: Use explicit LLVMContextRef for inlining 2023-09-27 13:02:21 +02:00
lib Make binaryheap available to frontend code. 2023-09-18 12:18:33 -07:00
libpq Avoid potential pfree on NULL on OpenSSL errors 2023-09-22 11:18:25 +02:00
main Remove obsolete defense against strxfrm() bugs. 2023-04-20 13:20:14 +12:00
nodes Catalog not-null constraints 2023-08-25 13:31:24 +02:00
optimizer Fix EvalPlanQual rechecking during MERGE. 2023-09-30 10:52:21 +01:00
parser Provide FORCE_NULL * and FORCE_NOT_NULL * options for COPY FROM 2023-09-30 12:34:41 -04:00
partitioning Add missing ObjectIdGetDatum() in syscache lookup calls for Oids 2023-07-20 15:18:25 +09:00
po Translation updates 2023-08-07 12:39:30 +02:00
port Add GUC parameter "huge_pages_status" 2023-07-06 14:42:36 +09:00
postmaster Move PG_TEMP_FILE* macros to file_utils.h. 2023-09-05 17:02:06 -07:00
regex All supported systems have locale_t. 2023-07-09 11:55:18 +12:00
replication Move tracking of in_streaming to PGOutputData 2023-09-28 09:33:51 +09:00
rewrite Add TupleDescGetDefault() 2023-09-27 18:52:40 +01:00
snowball Fix the install rule for snowball_create.sql. 2023-05-23 11:15:57 -04:00
statistics Take pg_attribute out of VacAttrStats 2023-07-03 07:18:57 +02:00
storage doc: correct reference to pg_relation in comment 2023-09-26 17:07:14 -04:00
tcop Fix recovery conflict SIGUSR1 handling. 2023-09-07 12:39:24 +12:00
tsearch Limit to_tsvector_byid's initial array allocation to something sane. 2023-09-25 11:50:28 -04:00
utils Fix datalen calculation in tsvectorrecv(). 2023-10-01 13:16:47 -04:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Add system view pg_wait_events 2023-08-20 15:35:02 +09:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Add missing gettext triggers 2023-05-10 13:51:51 +02:00