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

Commita18328b

Browse files
committed
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 parentd43a97e commita18328b

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,boolneed_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
returnmakeJsonLexContextCstringLen(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
elseif (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);
@@ -4461,6 +4469,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
44614469
if (keys_nulls[i])
44624470
continue;
44634471

4472+
/* We rely on the array elements not being toasted */
44644473
keyptr=VARDATA_ANY(keys_elems[i]);
44654474
keylen=VARSIZE_ANY_EXHDR(keys_elems[i]);
44664475
if (keylen==v.val.string.len&&
@@ -4985,13 +4994,19 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49854994
intpath_len,JsonbParseState**st,intlevel,
49864995
JsonbValue*newval,uint32npairs,intop_type)
49874996
{
4997+
text*pathelem=NULL;
49884998
inti;
49894999
JsonbValuek,
49905000
v;
49915001
booldone= false;
49925002

49935003
if (level >=path_len||path_nulls[level])
49945004
done= true;
5005+
else
5006+
{
5007+
/* The path Datum could be toasted, in which case we must detoast it */
5008+
pathelem=DatumGetTextPP(path_elems[level]);
5009+
}
49955010

49965011
/* empty object is a special case for create */
49975012
if ((npairs==0)&& (op_type&JB_PATH_CREATE_OR_INSERT)&&
@@ -5000,8 +5015,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50005015
JsonbValuenewkey;
50015016

50025017
newkey.type=jbvString;
5003-
newkey.val.string.len=VARSIZE_ANY_EXHDR(path_elems[level]);
5004-
newkey.val.string.val=VARDATA_ANY(path_elems[level]);
5018+
newkey.val.string.val=VARDATA_ANY(pathelem);
5019+
newkey.val.string.len=VARSIZE_ANY_EXHDR(pathelem);
50055020

50065021
(void)pushJsonbValue(st,WJB_KEY,&newkey);
50075022
(void)pushJsonbValue(st,WJB_VALUE,newval);
@@ -5014,8 +5029,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50145029
Assert(r==WJB_KEY);
50155030

50165031
if (!done&&
5017-
k.val.string.len==VARSIZE_ANY_EXHDR(path_elems[level])&&
5018-
memcmp(k.val.string.val,VARDATA_ANY(path_elems[level]),
5032+
k.val.string.len==VARSIZE_ANY_EXHDR(pathelem)&&
5033+
memcmp(k.val.string.val,VARDATA_ANY(pathelem),
50195034
k.val.string.len)==0)
50205035
{
50215036
done= true;
@@ -5055,8 +5070,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50555070
JsonbValuenewkey;
50565071

50575072
newkey.type=jbvString;
5058-
newkey.val.string.len=VARSIZE_ANY_EXHDR(path_elems[level]);
5059-
newkey.val.string.val=VARDATA_ANY(path_elems[level]);
5073+
newkey.val.string.val=VARDATA_ANY(pathelem);
5074+
newkey.val.string.len=VARSIZE_ANY_EXHDR(pathelem);
50605075

50615076
(void)pushJsonbValue(st,WJB_KEY,&newkey);
50625077
(void)pushJsonbValue(st,WJB_VALUE,newval);
@@ -5099,8 +5114,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
50995114
JsonbValuenewkey;
51005115

51015116
newkey.type=jbvString;
5102-
newkey.val.string.len=VARSIZE_ANY_EXHDR(path_elems[level]);
5103-
newkey.val.string.val=VARDATA_ANY(path_elems[level]);
5117+
newkey.val.string.val=VARDATA_ANY(pathelem);
5118+
newkey.val.string.len=VARSIZE_ANY_EXHDR(pathelem);
51045119

51055120
(void)pushJsonbValue(st,WJB_KEY,&newkey);
51065121
(void)push_path(st,level,path_elems,path_nulls,
@@ -5509,6 +5524,8 @@ transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
55095524
if ((type==WJB_VALUE||type==WJB_ELEM)&&v.type==jbvString)
55105525
{
55115526
out=transform_action(action_state,v.val.string.val,v.val.string.len);
5527+
/* out is probably not toasted, but let's be sure */
5528+
out=pg_detoast_datum_packed(out);
55125529
v.val.string.val=VARDATA_ANY(out);
55135530
v.val.string.len=VARSIZE_ANY_EXHDR(out);
55145531
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
@@ -5192,6 +5192,40 @@ DETAIL: The path assumes key is a composite object, but it is a scalar value.
51925192
update test_jsonb_subscript set test_json[0][0] = '1';
51935193
ERROR: cannot replace existing key
51945194
DETAIL: The path assumes key is a composite object, but it is a scalar value.
5195+
-- try some things with short-header and toasted subscript values
5196+
drop table test_jsonb_subscript;
5197+
create temp table test_jsonb_subscript (
5198+
id text,
5199+
test_json jsonb
5200+
);
5201+
insert into test_jsonb_subscript values('foo', '{"foo": "bar"}');
5202+
insert into test_jsonb_subscript
5203+
select s, ('{"' || s || '": "bar"}')::jsonb from repeat('xyzzy', 500) s;
5204+
select length(id), test_json[id] from test_jsonb_subscript;
5205+
length | test_json
5206+
--------+-----------
5207+
3 | "bar"
5208+
2500 | "bar"
5209+
(2 rows)
5210+
5211+
update test_jsonb_subscript set test_json[id] = '"baz"';
5212+
select length(id), test_json[id] from test_jsonb_subscript;
5213+
length | test_json
5214+
--------+-----------
5215+
3 | "baz"
5216+
2500 | "baz"
5217+
(2 rows)
5218+
5219+
\x
5220+
table test_jsonb_subscript;
5221+
-[ RECORD 1 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5222+
id | foo
5223+
test_json | {"foo": "baz"}
5224+
-[ RECORD 2 ]--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5225+
id | xyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzz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yxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzyxyzzy": "baz"}
5227+
5228+
\x
51955229
-- jsonb to tsvector
51965230
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::jsonb);
51975231
to_tsvector

‎src/test/regress/sql/jsonb.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,24 @@ insert into test_jsonb_subscript values (1, 'null');
14051405
update test_jsonb_subscriptset test_json[0]='1';
14061406
update test_jsonb_subscriptset test_json[0][0]='1';
14071407

1408+
-- try some things with short-header and toasted subscript values
1409+
1410+
droptable test_jsonb_subscript;
1411+
create temp table test_jsonb_subscript (
1412+
idtext,
1413+
test_json jsonb
1414+
);
1415+
1416+
insert into test_jsonb_subscriptvalues('foo','{"foo": "bar"}');
1417+
insert into test_jsonb_subscript
1418+
select s, ('{"'|| s||'": "bar"}')::jsonbfrom repeat('xyzzy',500) s;
1419+
select length(id), test_json[id]from test_jsonb_subscript;
1420+
update test_jsonb_subscriptset test_json[id]='"baz"';
1421+
select length(id), test_json[id]from test_jsonb_subscript;
1422+
\x
1423+
table test_jsonb_subscript;
1424+
\x
1425+
14081426
-- jsonb to tsvector
14091427
select to_tsvector('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'::jsonb);
14101428

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp