Skip to content

Commit

Permalink
Add assert for fetch_att and store_att_byval
Browse files Browse the repository at this point in the history
These two functions throw an error if you pass in a strange combination
of typbyval and typlen, so we assert on bad values to get a backtrace.
  • Loading branch information
mkindahl committed Oct 18, 2024
1 parent 4316f2c commit 4df3586
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@

#ifdef TS_DEBUG

static inline Datum
ts_fetch_att(const void *T, bool attbyval, int attlen)
{
/* Length should be set to something sensible, otherwise an error will be
* raised by fetch_att, so we assert this here to get a stack for
* violations. */
Assert(!attbyval || (attlen > 0 && attlen <= 8));
return fetch_att(T, attbyval, attlen);
}

static inline const char *
yes_no(bool value)
{
Expand Down
7 changes: 6 additions & 1 deletion tsl/src/compression/algorithms/datum_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ datum_to_bytes_and_advance(DatumSerializer *serializer, char *start, Size *max_s
start = align_and_zero(start, serializer->type_align, max_size);
data_length = serializer->type_len;
check_allowed_data_len(data_length, *max_size);

/* Data length should be set to something sensible, otherwise an error
* will be raised inside store_att_byval, so we assert here to get a
* stack. */
Assert(data_length > 0 && data_length <= 8);
store_att_byval(start, datum, data_length);
}
else if (serializer->type_len == -1)
Expand Down Expand Up @@ -322,7 +327,7 @@ bytes_to_datum_and_advance(DatumDeserializer *deserializer, const char **ptr)
CheckCompressedData((VARATT_IS_1B(*ptr) && VARSIZE_1B(*ptr) >= VARHDRSZ_SHORT) ||
(VARSIZE_4B(*ptr) > VARHDRSZ));
}
res = fetch_att(*ptr, deserializer->type_by_val, deserializer->type_len);
res = ts_fetch_att(*ptr, deserializer->type_by_val, deserializer->type_len);
*ptr = att_addlength_pointer(*ptr, deserializer->type_len, *ptr);
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion tsl/src/hypercore/arrow_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ arrow_get_datum_fixlen(const ArrowArray *array, Oid typid, int16 typlen, uint16
/* In order to handle fixed-length values of arbitrary size that are byref
* and byval, we use fetch_all() rather than rolling our own. This is
* taken from utils/adt/rangetypes.c */
Datum datum = fetch_att(&values[index * typlen], apriv->typbyval, typlen);
Datum datum = ts_fetch_att(&values[index * typlen], apriv->typbyval, typlen);

TS_DEBUG_LOG("retrieved fixlen value %s row %u from offset %u"
" in memory context %s",
Expand Down
2 changes: 1 addition & 1 deletion tsl/src/nodes/decompress_chunk/pred_vector_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ vector_array_predicate(VectorPredicate *vector_const_predicate, bool is_or,
}
return;
}
Datum constvalue = fetch_att(array_data, typbyval, typlen);
Datum constvalue = ts_fetch_att(array_data, typbyval, typlen);
array_data = att_addlength_pointer(array_data, typlen, array_data);
array_data = (const char *) att_align_nominal(array_data, typalign);

Expand Down

0 comments on commit 4df3586

Please sign in to comment.