Subject: | Retrieving BLOB truncates data |
I have a function which creates binary data (GIF or JPG), something like this:
select data2image(data, 'gif')
In DBD-Pg-1.43, 1.42, and 1.41 it worked well. With DBD-Pg-1.43_1, it truncates the BLOB to around 24 bytes, but only on one of my two Linux systems - the other one works.
Both systems are RedHat FC 3, but slightly different libraries.
This one works:
$ rpm -qa glibc
glibc-2.3.5-0.fc3.1
This one truncates the BLOB data (but only for DBD-Pg-1.43_1, DBD-Pg-1.43 works fine):
$ rpm -qa glibc
glibc-2.3.3-74
The C function looks roughly like this:
/* Postgres declaration */
PG_FUNCTION_INFO_V1(data2image);
Datum data2image(PG_FUNCTION_ARGS);
Datum
data2image(PG_FUNCTION_ARGS)
{
text *data_txt;
char *data, *image_type, *colorscheme;
int width, height, transparent, quality, data_len, image_len;
void *imageInfo, *image;
bytea *res;
data_txt = PG_GETARG_TEXT_P(0);
data_len = VARSIZE(data_txt) - VARHDRSZ;
data = palloc(data_len+1);
memcpy(data, VARDATA(data_txt), data_len);
data[data_len] = '\0';
image_type = PG_GETARG_CSTRING(1);
/* Draw the picture */
...
/* Copy image to PG output variable */
res = palloc(VARHDRSZ + image_len);
memcpy(VARDATA(res), image, image_len);
VARATT_SIZEP(res) = VARHDRSZ + image_len;
/* Return the new image */
PG_RETURN_BYTEA_P(res);
}