MCPcopy Create free account
hub / github.com/apache/cloudberry / array_recv

Function array_recv

src/backend/utils/adt/arrayfuncs.c:1273–1433  ·  view source on GitHub ↗

* array_recv : * converts an array from the external binary format to * its internal format. * * return value : * the internal representation of the input array */

Source from the content-addressed store, hash-verified

1271 * the internal representation of the input array
1272 */
1273Datum
1274array_recv(PG_FUNCTION_ARGS)
1275{
1276 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
1277 Oid spec_element_type = PG_GETARG_OID(1); /* type of an array
1278 * element */
1279 int32 typmod = PG_GETARG_INT32(2); /* typmod for array elements */
1280 Oid element_type;
1281 int typlen;
1282 bool typbyval;
1283 char typalign;
1284 Oid typioparam;
1285 int i,
1286 nitems;
1287 Datum *dataPtr;
1288 bool *nullsPtr;
1289 bool hasnulls;
1290 int32 nbytes;
1291 int32 dataoffset;
1292 ArrayType *retval;
1293 int ndim,
1294 flags,
1295 dim[MAXDIM],
1296 lBound[MAXDIM];
1297 ArrayMetaState *my_extra;
1298
1299 /* Get the array header information */
1300 ndim = pq_getmsgint(buf, 4);
1301 if (ndim < 0) /* we do allow zero-dimension arrays */
1302 ereport(ERROR,
1303 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1304 errmsg("invalid number of dimensions: %d", ndim)));
1305 if (ndim > MAXDIM)
1306 ereport(ERROR,
1307 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1308 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
1309 ndim, MAXDIM)));
1310
1311 flags = pq_getmsgint(buf, 4);
1312 if (flags != 0 && flags != 1)
1313 ereport(ERROR,
1314 (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
1315 errmsg("invalid array flags")));
1316
1317 /* Check element type recorded in the data */
1318 element_type = pq_getmsgint(buf, sizeof(Oid));
1319
1320 /*
1321 * From a security standpoint, it doesn't matter whether the input's
1322 * element type matches what we expect: the element type's receive
1323 * function has to be robust enough to cope with invalid data. However,
1324 * from a user-friendliness standpoint, it's nicer to complain about type
1325 * mismatches than to throw "improper binary format" errors. But there's
1326 * a problem: only built-in types have OIDs that are stable enough to
1327 * believe that a mismatch is a real issue. So complain only if both OIDs
1328 * are in the built-in range. Otherwise, carry on with the element type
1329 * we "should" be getting.
1330 */

Callers 2

oidvectorrecvFunction · 0.85
int2vectorrecvFunction · 0.85

Calls 15

pq_getmsgintFunction · 0.85
format_type_extendedFunction · 0.85
ArrayGetNItemsFunction · 0.85
ArrayCheckBoundsFunction · 0.85
MemoryContextAllocFunction · 0.85
get_type_io_dataFunction · 0.85
format_type_beFunction · 0.85
fmgr_info_cxtFunction · 0.85
construct_empty_arrayFunction · 0.85
ReadArrayBinaryFunction · 0.85
CopyArrayElsFunction · 0.85
errcodeFunction · 0.50

Tested by

no test coverage detected