mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType.
UBSan complains about this. Instead, cast to a suitable type requiring only 4-byte alignment. DatumGetAnyArrayP() already assumes one can cast between AnyArrayType and ArrayType, so this doesn't introduce a new assumption. Back-patch to 9.5, where AnyArrayType was introduced. Reviewed by Tom Lane. Discussion: https://postgr.es/m/20190629210334.GA1244217@rfd.leadboat.com
This commit is contained in:
@@ -153,7 +153,10 @@ typedef struct ExpandedArrayHeader
|
||||
|
||||
/*
|
||||
* Functions that can handle either a "flat" varlena array or an expanded
|
||||
* array use this union to work with their input.
|
||||
* array use this union to work with their input. Don't refer to "flt";
|
||||
* instead, cast to ArrayType. This struct nominally requires 8-byte
|
||||
* alignment on 64-bit, but it's often used for an ArrayType having 4-byte
|
||||
* alignment. UBSan complains about referencing "flt" in such cases.
|
||||
*/
|
||||
typedef union AnyArrayType
|
||||
{
|
||||
@@ -307,17 +310,21 @@ typedef struct ArrayIteratorData *ArrayIterator;
|
||||
* Macros for working with AnyArrayType inputs. Beware multiple references!
|
||||
*/
|
||||
#define AARR_NDIM(a) \
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.ndims : ARR_NDIM(&(a)->flt))
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? \
|
||||
(a)->xpn.ndims : ARR_NDIM((ArrayType *) (a)))
|
||||
#define AARR_HASNULL(a) \
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? \
|
||||
((a)->xpn.dvalues != NULL ? (a)->xpn.dnulls != NULL : ARR_HASNULL((a)->xpn.fvalue)) : \
|
||||
ARR_HASNULL(&(a)->flt))
|
||||
ARR_HASNULL((ArrayType *) (a)))
|
||||
#define AARR_ELEMTYPE(a) \
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.element_type : ARR_ELEMTYPE(&(a)->flt))
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? \
|
||||
(a)->xpn.element_type : ARR_ELEMTYPE((ArrayType *) (a)))
|
||||
#define AARR_DIMS(a) \
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.dims : ARR_DIMS(&(a)->flt))
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? \
|
||||
(a)->xpn.dims : ARR_DIMS((ArrayType *) (a)))
|
||||
#define AARR_LBOUND(a) \
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? (a)->xpn.lbound : ARR_LBOUND(&(a)->flt))
|
||||
(VARATT_IS_EXPANDED_HEADER(a) ? \
|
||||
(a)->xpn.lbound : ARR_LBOUND((ArrayType *) (a)))
|
||||
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user