Opened 5 years ago

Closed 5 years ago

#4451 closed defect (fixed)

gserialized_max_header_size is too big

Reported by: Algunenano Owned by: Algunenano
Priority: medium Milestone: PostGIS 3.0.0
Component: postgis Version: master
Keywords: Cc:

Description

The max header size is being calculated as:

return sizeof(GSERIALIZED) + 8 * sizeof(float) + sizeof(int);

But sizeof(GSERIALIZED) takes into account data[1], which AFAIK we shouldn't include as it's added after.

A small test case:

#include <stdio.h>
#include <stdint.h>

typedef struct
{
    uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
    uint8_t srid[3]; /* 24 bits of SRID */
    uint8_t gflags; /* HasZ, HasM, HasBBox, IsGeodetic */
    uint8_t data[1]; /* See gserialized.txt */
} GSERIALIZED;

int main()
{
	printf("Size: %d\n", sizeof(GSERIALIZED));
	printf("Data: %u\n", (intptr_t)&((GSERIALIZED *)NULL)->data);
}
$ ./a.out 
Size: 12
Data: 8

sizeof(GSERIALIZED) returns 12 bytes, when what we want is 8.

Change History (2)

comment:2 by Raul Marin, 5 years ago

Resolution: fixed
Status: assignedclosed

In 17585:

Fix the calculation of gserialized_max_header_size

Closes #4451
Closes https://github.com/postgis/postgis/pull/433

Note: See TracTickets for help on using tickets.