Opened 3 years ago
Closed 3 years ago
#4982 closed defect (fixed)
Problem when calling the buffer function from MobilityDB
Reported by: | ezimanyi | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 3.1.4 |
Component: | postgis | Version: | 2.5.x -- EOL |
Keywords: | Cc: |
Description
I get an error when calling the C function
Datum buffer(PG_FUNCTION_ARGS)
with only two arguments, the third one being optional
ERROR: invalid memory alloc request size 18446744073709551613
The problem is solved when I modify the function as follows
PG_FUNCTION_INFO_V1(buffer); Datum buffer(PG_FUNCTION_ARGS) { [...] text *params_text; if (PG_NARGS() > 2) { params_text = PG_GETARG_TEXT_P(2); } else { // params_text = palloc(VARHDRSZ); <- ORIGINAL DEFINITION // SET_VARSIZE(params_text, 0); params_text = cstring_to_text(""); // <- PROPOSED SOLUTION } [...] }
Change History (4)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
The code in cstring_to_text("") does:
int len = strlen(""); /* Should be 0 */ text *result = (text *) palloc(len + VARHDRSZ); SET_VARSIZE(result, len + VARHDRSZ); memcpy(VARDATA(result), s, len); return result;
So what we're missing is basically the VARHDRSZ in the SET_VARSIZE call (we're passing 0 rather than 0 + VARHDRSZ).
The patch is safe and more readable than doing this "manually", so I'd go for it.
Note:
See TracTickets
for help on using tickets.
pramsey have an opinion on this?