Skip to content

Commit d79b76b

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 8b5ba2f commit d79b76b

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
@@ -896,9 +896,10 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
896896
/* Nulls in the array are ignored */
897897
if (key_nulls[i])
898898
continue;
899+
/* We rely on the array elements not being toasted */
899900
entries[j++] = make_text_key(JGINFLAG_KEY,
900-
VARDATA(key_datums[i]),
901-
VARSIZE(key_datums[i]) - VARHDRSZ);
901+
VARDATA_ANY(key_datums[i]),
902+
VARSIZE_ANY_EXHDR(key_datums[i]));
902903
}
903904

904905
*nentries = j;

src/backend/utils/adt/jsonb_op.c

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

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

7071
if (findJsonbValueFromContainer(&jb->root,
7172
JB_FOBJECT | JB_FARRAY,
@@ -97,8 +98,9 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
9798
continue;
9899

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

103105
if (findJsonbValueFromContainer(&jb->root,
104106
JB_FOBJECT | JB_FARRAY,

src/backend/utils/adt/jsonfuncs.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ pg_parse_json_or_ereport(JsonLexContext *lex, JsonSemAction *sem)
516516
JsonLexContext *
517517
makeJsonLexContext(text *json, bool need_escapes)
518518
{
519+
/*
520+
* Most callers pass a detoasted datum, but it's not clear that they all
521+
* do. pg_detoast_datum_packed() is cheap insurance.
522+
*/
523+
json = pg_detoast_datum_packed(json);
524+
519525
return makeJsonLexContextCstringLen(VARDATA_ANY(json),
520526
VARSIZE_ANY_EXHDR(json),
521527
GetDatabaseEncoding(),
@@ -1518,9 +1524,11 @@ jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
15181524
{
15191525
if (have_object)
15201526
{
1527+
text *subscr = DatumGetTextPP(path[i]);
1528+
15211529
jbvp = getKeyJsonValueFromContainer(container,
1522-
VARDATA(path[i]),
1523-
VARSIZE(path[i]) - VARHDRSZ,
1530+
VARDATA_ANY(subscr),
1531+
VARSIZE_ANY_EXHDR(subscr),
15241532
NULL);
15251533
}
15261534
else if (have_array)
@@ -1693,8 +1701,8 @@ push_path(JsonbParseState **st, int level, Datum *path_elems,
16931701
{
16941702
/* text, an object is expected */
16951703
newkey.type = jbvString;
1696-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[i]);
1697-
newkey.val.string.val = VARDATA_ANY(path_elems[i]);
1704+
newkey.val.string.val = c;
1705+
newkey.val.string.len = strlen(c);
16981706

16991707
(void) pushJsonbValue(st, WJB_BEGIN_OBJECT, NULL);
17001708
(void) pushJsonbValue(st, WJB_KEY, &newkey);
@@ -4349,6 +4357,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
43494357
if (keys_nulls[i])
43504358
continue;
43514359

4360+
/* We rely on the array elements not being toasted */
43524361
keyptr = VARDATA_ANY(keys_elems[i]);
43534362
keylen = VARSIZE_ANY_EXHDR(keys_elems[i]);
43544363
if (keylen == v.val.string.len &&
@@ -4873,13 +4882,19 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
48734882
int path_len, JsonbParseState **st, int level,
48744883
JsonbValue *newval, uint32 npairs, int op_type)
48754884
{
4885+
text *pathelem = NULL;
48764886
int i;
48774887
JsonbValue k,
48784888
v;
48794889
bool done = false;
48804890

48814891
if (level >= path_len || path_nulls[level])
48824892
done = true;
4893+
else
4894+
{
4895+
/* The path Datum could be toasted, in which case we must detoast it */
4896+
pathelem = DatumGetTextPP(path_elems[level]);
4897+
}
48834898

48844899
/* empty object is a special case for create */
48854900
if ((npairs == 0) && (op_type & JB_PATH_CREATE_OR_INSERT) &&
@@ -4888,8 +4903,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
48884903
JsonbValue newkey;
48894904

48904905
newkey.type = jbvString;
4891-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4892-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4906+
newkey.val.string.val = VARDATA_ANY(pathelem);
4907+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
48934908

48944909
(void) pushJsonbValue(st, WJB_KEY, &newkey);
48954910
(void) pushJsonbValue(st, WJB_VALUE, newval);
@@ -4902,8 +4917,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49024917
Assert(r == WJB_KEY);
49034918

49044919
if (!done &&
4905-
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
4906-
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
4920+
k.val.string.len == VARSIZE_ANY_EXHDR(pathelem) &&
4921+
memcmp(k.val.string.val, VARDATA_ANY(pathelem),
49074922
k.val.string.len) == 0)
49084923
{
49094924
done = true;
@@ -4943,8 +4958,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49434958
JsonbValue newkey;
49444959

49454960
newkey.type = jbvString;
4946-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4947-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4961+
newkey.val.string.val = VARDATA_ANY(pathelem);
4962+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
49484963

49494964
(void) pushJsonbValue(st, WJB_KEY, &newkey);
49504965
(void) pushJsonbValue(st, WJB_VALUE, newval);
@@ -4987,8 +5002,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49875002
JsonbValue newkey;
49885003

49895004
newkey.type = jbvString;
4990-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4991-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
5005+
newkey.val.string.val = VARDATA_ANY(pathelem);
5006+
newkey.val.string.len = VARSIZE_ANY_EXHDR(pathelem);
49925007

49935008
(void) pushJsonbValue(st, WJB_KEY, &newkey);
49945009
(void) push_path(st, level, path_elems, path_nulls,
@@ -5397,6 +5412,8 @@ transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
53975412
if ((type == WJB_VALUE || type == WJB_ELEM) && v.type == jbvString)
53985413
{
53995414
out = transform_action(action_state, v.val.string.val, v.val.string.len);
5415+
/* out is probably not toasted, but let's be sure */
5416+
out = pg_detoast_datum_packed(out);
54005417
v.val.string.val = VARDATA_ANY(out);
54015418
v.val.string.len = VARSIZE_ANY_EXHDR(out);
54025419
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
@@ -5199,6 +5199,40 @@ DETAIL: The path assumes key is a composite object, but it is a scalar value.
51995199
update test_jsonb_subscript set test_json[0][0] = '1';
52005200
ERROR: cannot replace existing key
52015201
DETAIL: The path assumes key is a composite object, but it is a scalar value.
5202+
-- try some things with short-header and toasted subscript values
5203+
drop table test_jsonb_subscript;
5204+
create temp table test_jsonb_subscript (
5205+
id text,
5206+
test_json jsonb
5207+
);
5208+
insert into test_jsonb_subscript values('foo', '{"foo": "bar"}');
5209+
insert into test_jsonb_subscript
5210+
select s, ('{"' || s || '": "bar"}')::jsonb from repeat('xyzzy', 500) s;
5211+
select length(id), test_json[id] from test_jsonb_subscript;
5212+
length | test_json
5213+
--------+-----------
5214+
3 | "bar"
5215+
2500 | "bar"
5216+
(2 rows)
5217+
5218+
update test_jsonb_subscript set test_json[id] = '"baz"';
5219+
select length(id), test_json[id] from test_jsonb_subscript;
5220+
length | test_json
5221+
--------+-----------
5222+
3 | "baz"
5223+
2500 | "baz"
5224+
(2 rows)
5225+
5226+
\x
5227+
table test_jsonb_subscript;
5228+
-[ RECORD 1 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5229+
id | foo
5230+
test_json | {"foo": "baz"}
5231+
-[ RECORD 2 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5232+
id | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzy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xyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzy": "baz"}
5234+
5235+
\x
52025236
-- jsonb to tsvector
52035237
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::jsonb);
52045238
to_tsvector

src/test/regress/sql/jsonb.sql

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

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

0 commit comments

Comments
 (0)