PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_from_twkb()

LWGEOM* lwgeom_from_twkb ( uint8_t twkb,
size_t  twkb_size,
char  check 
)

WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory segment (this stops a malevolent user from declaring a one-ring polygon to have 10 rings, causing the WKB reader to walk off the end of the memory).

Parameters
checkparser check flags, see LW_PARSER_CHECK_* macros
sizeparser check flags, see LW_PARSER_CHECK_* macros

Check is a bitmask of: LW_PARSER_CHECK_MINPOINTS, LW_PARSER_CHECK_ODD, LW_PARSER_CHECK_CLOSURE, LW_PARSER_CHECK_NONE, LW_PARSER_CHECK_ALL

Definition at line 656 of file lwin_twkb.c.

References twkb_parse_state::check, twkb_parse_state::coords, LW_PARSER_CHECK_NONE, LWDEBUG, LWDEBUGF, lwgeom_from_twkb_state(), twkb_parse_state::pos, s, twkb_parse_state::twkb, twkb_parse_state::twkb_end, and TWKB_IN_MAXCOORDS.

Referenced by cu_twkb_idlist(), cu_twkb_in(), and LWGEOMFromTWKB().

657 {
658  int64_t coords[TWKB_IN_MAXCOORDS] = {0, 0, 0, 0};
660 
661  LWDEBUG(2,"Entering lwgeom_from_twkb");
662  LWDEBUGF(4,"twkb_size: %d",(int) twkb_size);
663 
664  /* Zero out the state */
665  memset(&s, 0, sizeof(twkb_parse_state));
666 
667  /* Initialize the state appropriately */
668  s.twkb = s.pos = twkb;
669  s.twkb_end = twkb + twkb_size;
670  s.check = check;
671  s.coords = coords;
672 
673  /* Handle the check catch-all values */
674  if ( check & LW_PARSER_CHECK_NONE )
675  s.check = 0;
676  else
677  s.check = check;
678 
679 
680  /* Read the rest of the geometry */
681  return lwgeom_from_twkb_state(&s);
682 }
uint32_t check
Definition: lwin_twkb.c:43
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint8_t * pos
Definition: lwin_twkb.c:41
uint8_t * twkb_end
Definition: lwin_twkb.c:40
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
#define TWKB_IN_MAXCOORDS
Definition: lwin_twkb.c:31
int64_t * coords
Definition: lwin_twkb.c:65
char * s
Definition: cu_in_wkt.c:23
Used for passing the parse state between the parsing functions.
Definition: lwin_twkb.c:36
LWGEOM * lwgeom_from_twkb_state(twkb_parse_state *s)
Internal function declarations.
Definition: lwin_twkb.c:562
uint8_t * twkb
Definition: lwin_twkb.c:39
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
Here is the call graph for this function:
Here is the caller graph for this function: