Skip to content

Commit b0feda7

Browse files
committed
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
1 parent 101c37c commit b0feda7

File tree

5 files changed

+90
-18
lines changed

5 files changed

+90
-18
lines changed

src/backend/utils/adt/jsonb_gin.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,10 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
894894
/* Nulls in the array are ignored */
895895
if (key_nulls[i])
896896
continue;
897+
/* We rely on the array elements not being toasted */
897898
entries[j++] = make_text_key(JGINFLAG_KEY,
898-
VARDATA(key_datums[i]),
899-
VARSIZE(key_datums[i]) - VARHDRSZ);
899+
VARDATA_ANY(key_datums[i]),
900+
VARSIZE_ANY_EXHDR(key_datums[i]));
900901
}
901902

902903
*nentries = j;

src/backend/utils/adt/jsonb_op.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
6363
continue;
6464

6565
strVal.type = jbvString;
66-
strVal.val.string.val = VARDATA(key_datums[i]);
67-
strVal.val.string.len = VARSIZE(key_datums[i]) - VARHDRSZ;
66+
/* We rely on the array elements not being toasted */
67+
strVal.val.string.val = VARDATA_ANY(key_datums[i]);
68+
strVal.val.string.len = VARSIZE_ANY_EXHDR(key_datums[i]);
6869

6970
if (findJsonbValueFromContainer(&jb->root,
7071
JB_FOBJECT | JB_FARRAY,
@@ -95,8 +96,9 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
9596
continue;
9697

9798
strVal.type = jbvString;
98-
strVal.val.string.val = VARDATA(key_datums[i]);
99-
strVal.val.string.len = VARSIZE(key_datums[i]) - VARHDRSZ;
99+
/* We rely on the array elements not being toasted */
100+
strVal.val.string.val = VARDATA_ANY(key_datums[i]);
101+
strVal.val.string.len = VARSIZE_ANY_EXHDR(key_datums[i]);
100102

101103
if (findJsonbValueFromContainer(&jb->root,
102104
JB_FOBJECT | JB_FARRAY,

src/backend/utils/adt/jsonfuncs.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem,
527527
JsonLexContext *
528528
makeJsonLexContext(text *json, bool need_escapes)
529529
{
530+
/*
531+
* Most callers pass a detoasted datum, but it's not clear that they all
532+
* do. pg_detoast_datum_packed() is cheap insurance.
533+
*/
534+
json = pg_detoast_datum_packed(json);
535+
530536
return makeJsonLexContextCstringLen(VARDATA_ANY(json),
531537
VARSIZE_ANY_EXHDR(json),
532538
GetDatabaseEncoding(),
@@ -1559,9 +1565,11 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
15591565
{
15601566
if (have_object)
15611567
{
1568+
text *subscr = DatumGetTextPP(path[i]);
1569+
15621570
jbvp = getKeyJsonValueFromContainer(container,
1563-
VARDATA(path[i]),
1564-
VARSIZE(path[i]) - VARHDRSZ,
1571+
VARDATA_ANY(subscr),
1572+
VARSIZE_ANY_EXHDR(subscr),
15651573
NULL);
15661574
}
15671575
else if (have_array)
@@ -1734,8 +1742,8 @@ push_path(JsonbParseState **st, int level, Datum *path_elems,
17341742
{
17351743
/* text, an object is expected */
17361744
newkey.type = jbvString;
1737-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[i]);
1738-
newkey.val.string.val = VARDATA_ANY(path_elems[i]);
1745+
newkey.val.string.val = c;
1746+
newkey.val.string.len = strlen(c);
17391747

17401748
(void) pushJsonbValue(st, WJB_BEGIN_OBJECT, NULL);
17411749
(void) pushJsonbValue(st, WJB_KEY, &newkey);
@@ -4456,6 +4464,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
44564464
if (keys_nulls[i])
44574465
continue;
44584466

4467+
/* We rely on the array elements not being toasted */
44594468
keyptr = VARDATA_ANY(keys_elems[i]);
44604469
keylen = VARSIZE_ANY_EXHDR(keys_elems[i]);
44614470
if (keylen == v.val.string.len &&
@@ -4977,13 +4986,19 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49774986
int path_len, JsonbParseState **st, int level,
49784987
JsonbValue *newval, uint32 npairs, int op_type)
49794988
{
4989+
text *pathelem = NULL;
49804990
int i;
49814991
JsonbValue k,
49824992
v;
49834993
bool done = false;
49844994

49854995
if (level >= path_len || path_nulls[level])
49864996
done = true;
4997+
else
4998+
{
4999+
/* The path Datum could be toasted, in which case we must detoast it */
5000+
pathelem = DatumGetTextPP(path_elems[level]);
5001+
}
49875002

49885003
/* empty object is a special case for create */
49895004
if ((npairs == 0) && (op_type & JB_PATH_CREATE_OR_INSERT) &&
@@ -4992,8 +5007,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49925007
JsonbValue newkey;
49935008

49945009
newkey.type = jbvString;
4995-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4996-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
5010+
newkey.val.string.val = VARDATA_ANY(pathelem);
5011+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
49975012

49985013
(void) pushJsonbValue(st, WJB_KEY, &newkey);
49995014
(void) pushJsonbValue(st, WJB_VALUE, newval);
@@ -5006,8 +5021,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50065021
Assert(r == WJB_KEY);
50075022

50085023
if (!done &&
5009-
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
5010-
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
5024+
k.val.string.len == VARSIZE_ANY_EXHDR(pathelem) &&
5025+
memcmp(k.val.string.val, VARDATA_ANY(pathelem),
50115026
k.val.string.len) == 0)
50125027
{
50135028
done = true;
@@ -5047,8 +5062,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50475062
JsonbValue newkey;
50485063

50495064
newkey.type = jbvString;
5050-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
5051-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
5065+
newkey.val.string.val = VARDATA_ANY(pathelem);
5066+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
50525067

50535068
(void) pushJsonbValue(st, WJB_KEY, &newkey);
50545069
(void) pushJsonbValue(st, WJB_VALUE, newval);
@@ -5091,8 +5106,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50915106
JsonbValue newkey;
50925107

50935108
newkey.type = jbvString;
5094-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
5095-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
5109+
newkey.val.string.val = VARDATA_ANY(pathelem);
5110+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
50965111

50975112
(void) pushJsonbValue(st, WJB_KEY, &newkey);
50985113
(void) push_path(st, level, path_elems, path_nulls,
@@ -5505,6 +5520,8 @@ transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
55055520
if ((type == WJB_VALUE || type == WJB_ELEM) && v.type == jbvString)
55065521
{
55075522
out = transform_action(action_state, v.val.string.val, v.val.string.len);
5523+
/* out is probably not toasted, but let's be sure */
5524+
out = pg_detoast_datum_packed(out);
55085525
v.val.string.val = VARDATA_ANY(out);
55095526
v.val.string.len = VARSIZE_ANY_EXHDR(out);
55105527
res = pushJsonbValue(&st, type, type < WJB_BEGIN_ARRAY ? &v : NULL);

src/test/regress/expected/jsonb.out

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,40 @@ DETAIL: The path assumes key is a composite object, but it is a scalar value.
52245224
update test_jsonb_subscript set test_json[0][0] = '1';
52255225
ERROR: cannot replace existing key
52265226
DETAIL: The path assumes key is a composite object, but it is a scalar value.
5227+
-- try some things with short-header and toasted subscript values
5228+
drop table test_jsonb_subscript;
5229+
create temp table test_jsonb_subscript (
5230+
id text,
5231+
test_json jsonb
5232+
);
5233+
insert into test_jsonb_subscript values('foo', '{"foo": "bar"}');
5234+
insert into test_jsonb_subscript
5235+
select s, ('{"' || s || '": "bar"}')::jsonb from repeat('xyzzy', 500) s;
5236+
select length(id), test_json[id] from test_jsonb_subscript;
5237+
length | test_json
5238+
--------+-----------
5239+
3 | "bar"
5240+
2500 | "bar"
5241+
(2 rows)
5242+
5243+
update test_jsonb_subscript set test_json[id] = '"baz"';
5244+
select length(id), test_json[id] from test_jsonb_subscript;
5245+
length | test_json
5246+
--------+-----------
5247+
3 | "baz"
5248+
2500 | "baz"
5249+
(2 rows)
5250+
5251+
\x
5252+
table test_jsonb_subscript;
5253+
-[ RECORD 1 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5254+
id | foo
5255+
test_json | {"foo": "baz"}
5256+
-[ RECORD 2 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5257+
id | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyz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zyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzy": "baz"}
5259+
5260+
\x
52275261
-- jsonb to tsvector
52285262
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::jsonb);
52295263
to_tsvector

src/test/regress/sql/jsonb.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,24 @@ insert into test_jsonb_subscript values (1, 'null');
14211421
update test_jsonb_subscript set test_json[0] = '1';
14221422
update test_jsonb_subscript set test_json[0][0] = '1';
14231423

1424+
-- try some things with short-header and toasted subscript values
1425+
1426+
drop table test_jsonb_subscript;
1427+
create temp table test_jsonb_subscript (
1428+
id text,
1429+
test_json jsonb
1430+
);
1431+
1432+
insert into test_jsonb_subscript values('foo', '{"foo": "bar"}');
1433+
insert into test_jsonb_subscript
1434+
select s, ('{"' || s || '": "bar"}')::jsonb from repeat('xyzzy', 500) s;
1435+
select length(id), test_json[id] from test_jsonb_subscript;
1436+
update test_jsonb_subscript set test_json[id] = '"baz"';
1437+
select length(id), test_json[id] from test_jsonb_subscript;
1438+
\x
1439+
table test_jsonb_subscript;
1440+
\x
1441+
14241442
-- jsonb to tsvector
14251443
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::jsonb);
14261444

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy