postgresql/src/backend
Tom Lane b0feda79fd Fix jsonb subscripting to cope with toasted subscript values.
jsonb_get_element() was incautious enough to use VARDATA() and
VARSIZE() directly on an arbitrary text Datum.  That of course
fails if the Datum is short-header, compressed, or out-of-line.
The typical result would be failing to match any element of a
jsonb object, though matching the wrong one seems possible as well.

setPathObject() was slightly brighter, in that it used VARDATA_ANY
and VARSIZE_ANY_EXHDR, but that only kept it out of trouble for
short-header Datums.  push_path() had the same issue.  This could
result in faulty subscripted insertions, though keys long enough to
cause a problem are likely rare in the wild.

Having seen these, I looked around for unsafe usages in the rest
of the adt/json* files.  There are a couple of places where it's not
immediately obvious that the Datum can't be compressed or out-of-line,
so I added pg_detoast_datum_packed() to cope if it is.  Also, remove
some other usages of VARDATA/VARSIZE on Datums we just extracted from
a text array.  Those aren't actively broken, but they will become so
if we ever start allowing short-header array elements, which does not
seem like a terribly unreasonable thing to do.  In any case they are
not great coding examples, and they could also do with comments
pointing out that we're assuming we don't need pg_detoast_datum_packed.

Per report from exe-dealer@yandex.ru.  Patch by me, but thanks to
David Johnston for initial investigation.  Back-patch to v14 where
jsonb subscripting was introduced.

Discussion: https://postgr.es/m/205321670615953@mail.yandex.ru
2022-12-12 16:17:54 -05:00
..
access Allow DateTimeParseError to handle bad-timezone error messages. 2022-12-09 13:30:47 -05:00
backup Fix failure to advance content pointer in sendFileWithContent. 2022-12-12 10:26:48 -05:00
bootstrap Order getopt arguments 2022-12-12 15:20:00 +01:00
catalog Add USER SET parameter values for pg_db_role_setting 2022-12-09 13:12:20 +03:00
commands Get rid of recursion-marker values in enum AlterTableType 2022-12-12 11:13:26 +01:00
executor Remove unnecessary casts 2022-12-08 08:58:15 +01:00
foreign Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
jit Replace SQLValueFunction by COERCE_SQL_SYNTAX 2022-11-21 18:31:59 +09:00
lib Add doubly linked count list implementation 2022-11-02 14:06:05 +13:00
libpq Fix typo in hba.c 2022-11-26 10:14:18 +09:00
main Add workaround to make ubsan and ps_status.c compatible 2022-11-21 13:56:23 -08:00
nodes Create infrastructure for "soft" error reporting. 2022-12-09 09:58:38 -05:00
optimizer Add subquery pullup handling for WindowClause runCondition 2022-12-10 19:27:20 +13:00
parser Get rid of recursion-marker values in enum AlterTableType 2022-12-12 11:13:26 +01:00
partitioning Move PartitioPruneInfo out of plan nodes into PlannedStmt 2022-12-01 12:56:21 +01:00
po meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
port Provide sigaction() for Windows. 2022-11-09 13:06:31 +13:00
postmaster Order getopt arguments 2022-12-12 15:20:00 +01:00
regex Remove uses of register due to incompatibility with C++17 and up 2022-09-24 12:08:37 -07:00
replication Avoid unnecessary streaming of transactions during logical replication. 2022-12-08 06:05:09 +05:30
rewrite Update outdated comment in ApplyRetrieveRule 2022-12-07 12:35:59 +01:00
snowball meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
statistics Stop accessing checkAsUser via RTE in some cases 2022-11-30 12:07:03 +01:00
storage Update types in File API 2022-12-08 08:58:15 +01:00
tcop Order getopt arguments 2022-12-12 15:20:00 +01:00
tsearch Add comments and a missing CHECK_FOR_INTERRUPTS in ts_headline. 2022-11-21 17:07:29 -05:00
utils Fix jsonb subscripting to cope with toasted subscript values. 2022-12-12 16:17:54 -05:00
.gitignore
Makefile autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00