Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit831e8c3

Browse files
tglsfdcpull[bot]
authored andcommitted
Fix jsonb subscripting to cope with toasted subscript values.
jsonb_get_element() was incautious enough to use VARDATA() andVARSIZE() directly on an arbitrary text Datum. That of coursefails if the Datum is short-header, compressed, or out-of-line.The typical result would be failing to match any element of ajsonb object, though matching the wrong one seems possible as well.setPathObject() was slightly brighter, in that it used VARDATA_ANYand VARSIZE_ANY_EXHDR, but that only kept it out of trouble forshort-header Datums. push_path() had the same issue. This couldresult in faulty subscripted insertions, though keys long enough tocause a problem are likely rare in the wild.Having seen these, I looked around for unsafe usages in the restof the adt/json* files. There are a couple of places where it's notimmediately 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, removesome other usages of VARDATA/VARSIZE on Datums we just extracted froma text array. Those aren't actively broken, but they will become soif we ever start allowing short-header array elements, which does notseem like a terribly unreasonable thing to do. In any case they arenot great coding examples, and they could also do with commentspointing 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 toDavid Johnston for initial investigation. Back-patch to v14 wherejsonb subscripting was introduced.Discussion:https://postgr.es/m/205321670615953@mail.yandex.ru
1 parentf1fb311 commit831e8c3

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,boolneed_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
returnmakeJsonLexContextCstringLen(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
elseif (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
intpath_len,JsonbParseState**st,intlevel,
49784987
JsonbValue*newval,uint32npairs,intop_type)
49794988
{
4989+
text*pathelem=NULL;
49804990
inti;
49814991
JsonbValuek,
49824992
v;
49834993
booldone= 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
JsonbValuenewkey;
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
JsonbValuenewkey;
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
JsonbValuenewkey;
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 | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyx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yzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzy": "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_subscriptset test_json[0]='1';
14221422
update test_jsonb_subscriptset test_json[0][0]='1';
14231423

1424+
-- try some things with short-header and toasted subscript values
1425+
1426+
droptable test_jsonb_subscript;
1427+
create temp table test_jsonb_subscript (
1428+
idtext,
1429+
test_json jsonb
1430+
);
1431+
1432+
insert into test_jsonb_subscriptvalues('foo','{"foo": "bar"}');
1433+
insert into test_jsonb_subscript
1434+
select s, ('{"'|| s||'": "bar"}')::jsonbfrom repeat('xyzzy',500) s;
1435+
select length(id), test_json[id]from test_jsonb_subscript;
1436+
update test_jsonb_subscriptset 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)

[8]ページ先頭

©2009-2025 Movatter.jp