Re: BUG #17858: ExecEvalArrayExpr() leaves uninitialised memory for multidim array with nulls
Alexander Law <exclusion@gmail.com>
From: Alexander Lakhin <exclusion@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>, pgsql-bugs@lists.postgresql.org
Date: 2023-03-21T13:00:00Z
Lists: pgsql-bugs
Hi Richard, 21.03.2023 14:52, Richard Guo wrote: > Nice catch. This can also be seen on master. > > I searched the codes a little bit and found that in array_set_slice() > and array_set_element() the 'newarray' is allocated with palloc0 and > then the nulls bitmap is zeroed with > > MemSet(nullbitmap, 0, (nitems + 7) / 8); > > if havenulls is true. I wonder if we can do the same here. I'm afraid that zeroing only bytes behind nitems bits is not enough, as outDatum() doesn't bother to calculate the exact size of nulls bitmap, it just outputs all bytes of a datum (40 bytes in that case): length = datumGetSize(value, typbyval, typlen); ... for (i = 0; i < length; i++) appendStringInfo(str, "%d ", (int) (s[i])); Best regards, Alexander
Commits
-
Fix oversights in array manipulation.
- ae320fc21686 11.20 landed
- ad5fe7420594 12.15 landed
- 7c4873438fd4 15.3 landed
- 554841699f0e 16.0 landed
- 1bbbe14607c3 13.11 landed
- 11213d44663e 14.8 landed
-
Fix array- and path-creating functions to ensure padding bytes are zeroes.
- 18c0b4eccdc8 9.1.0 cited