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

Commited84942

Browse files
committed
Fix array- and path-creating functions to ensure padding bytes are zeroes.
Per recent discussion, it's important for all computed datums (not only theresults of input functions) to not contain any ill-defined (uninitialized)bits. Failing to ensure that can result in equal() reporting thatsemantically indistinguishable Consts are not equal, which in turn leads tobizarre and undesirable planner behavior, such as in a recent example fromDavid Johnston. We might eventually try to fix this in a general manner byallowing datatypes to define identity-testing functions, but for now thepath of least resistance is to expect datatypes to force all unused bitsinto consistent states.Per some testing by Noah Misch, array and path functions seem to be theonly ones presenting risks at the moment, so I looked through all thefunctions in adt/array*.c and geo_ops.c and fixed them as necessary. Inthe array functions, the easiest/safest fix is to allocate result arrayswith palloc0 instead of palloc. Possibly in future someone will want tolook into whether we can just zero the padding bytes, but that looks toocomplex for a back-patchable fix. In the path functions, we already had aprecedent in path_in for just zeroing the one known pad field, so duplicatethat code as needed.Back-patch to all supported branches.
1 parentd3964cd commited84942

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

‎src/backend/utils/adt/array_userfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ array_cat(PG_FUNCTION_ARGS)
375375
dataoffset=0;/* marker for no null bitmap */
376376
nbytes=ndatabytes+ARR_OVERHEAD_NONULLS(ndims);
377377
}
378-
result= (ArrayType*)palloc(nbytes);
378+
result= (ArrayType*)palloc0(nbytes);
379379
result->size=nbytes;
380380
result->ndim=ndims;
381381
result->dataoffset=dataoffset;

‎src/backend/utils/adt/arrayfuncs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ array_recv(PG_FUNCTION_ARGS)
12781278
dataoffset=0;/* marker for no null bitmap */
12791279
nbytes+=ARR_OVERHEAD_NONULLS(ndim);
12801280
}
1281-
retval= (ArrayType*)palloc(nbytes);
1281+
retval= (ArrayType*)palloc0(nbytes);
12821282
retval->size=nbytes;
12831283
retval->ndim=ndim;
12841284
retval->dataoffset=dataoffset;
@@ -1878,7 +1878,7 @@ array_get_slice(ArrayType *array,
18781878
bytes+=ARR_OVERHEAD_NONULLS(ndim);
18791879
}
18801880

1881-
newarray= (ArrayType*)palloc(bytes);
1881+
newarray= (ArrayType*)palloc0(bytes);
18821882
newarray->size=bytes;
18831883
newarray->ndim=ndim;
18841884
newarray->dataoffset=dataoffset;
@@ -2131,7 +2131,7 @@ array_set(ArrayType *array,
21312131
/*
21322132
* OK, create the new array and fill in header/dimensions
21332133
*/
2134-
newarray= (ArrayType*)palloc(newsize);
2134+
newarray= (ArrayType*)palloc0(newsize);
21352135
newarray->size=newsize;
21362136
newarray->ndim=ndim;
21372137
newarray->dataoffset=newhasnulls ?overheadlen :0;
@@ -2461,7 +2461,7 @@ array_set_slice(ArrayType *array,
24612461

24622462
newsize=overheadlen+olddatasize-olditemsize+newitemsize;
24632463

2464-
newarray= (ArrayType*)palloc(newsize);
2464+
newarray= (ArrayType*)palloc0(newsize);
24652465
newarray->size=newsize;
24662466
newarray->ndim=ndim;
24672467
newarray->dataoffset=newhasnulls ?overheadlen :0;
@@ -2720,7 +2720,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType,
27202720
dataoffset=0;/* marker for no null bitmap */
27212721
nbytes+=ARR_OVERHEAD_NONULLS(ndim);
27222722
}
2723-
result= (ArrayType*)palloc(nbytes);
2723+
result= (ArrayType*)palloc0(nbytes);
27242724
result->size=nbytes;
27252725
result->ndim=ndim;
27262726
result->dataoffset=dataoffset;
@@ -2856,7 +2856,7 @@ construct_md_array(Datum *elems,
28562856
dataoffset=0;/* marker for no null bitmap */
28572857
nbytes+=ARR_OVERHEAD_NONULLS(ndims);
28582858
}
2859-
result= (ArrayType*)palloc(nbytes);
2859+
result= (ArrayType*)palloc0(nbytes);
28602860
result->size=nbytes;
28612861
result->ndim=ndims;
28622862
result->dataoffset=dataoffset;
@@ -2880,7 +2880,7 @@ construct_empty_array(Oid elmtype)
28802880
{
28812881
ArrayType*result;
28822882

2883-
result= (ArrayType*)palloc(sizeof(ArrayType));
2883+
result= (ArrayType*)palloc0(sizeof(ArrayType));
28842884
result->size=sizeof(ArrayType);
28852885
result->ndim=0;
28862886
result->dataoffset=0;

‎src/backend/utils/adt/geo_ops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,8 @@ path_recv(PG_FUNCTION_ARGS)
14761476
path->size=size;
14771477
path->npts=npts;
14781478
path->closed= (closed ?1 :0);
1479+
/* prevent instability in unused pad bytes */
1480+
path->dummy=0;
14791481

14801482
for (i=0;i<npts;i++)
14811483
{
@@ -4090,6 +4092,8 @@ path_add(PG_FUNCTION_ARGS)
40904092
result->size=size;
40914093
result->npts= (p1->npts+p2->npts);
40924094
result->closed=p1->closed;
4095+
/* prevent instability in unused pad bytes */
4096+
result->dummy=0;
40934097

40944098
for (i=0;i<p1->npts;i++)
40954099
{
@@ -4323,6 +4327,8 @@ poly_path(PG_FUNCTION_ARGS)
43234327
path->size=size;
43244328
path->npts=poly->npts;
43254329
path->closed= TRUE;
4330+
/* prevent instability in unused pad bytes */
4331+
path->dummy=0;
43264332

43274333
for (i=0;i<poly->npts;i++)
43284334
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp