PostGIS  2.2.8dev-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).

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 642 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().

643 {
644  int64_t coords[TWKB_IN_MAXCOORDS] = {0, 0, 0, 0};
646 
647  LWDEBUG(2,"Entering lwgeom_from_twkb");
648  LWDEBUGF(4,"twkb_size: %d",(int) twkb_size);
649 
650  /* Zero out the state */
651  memset(&s, 0, sizeof(twkb_parse_state));
652 
653  /* Initialize the state appropriately */
654  s.twkb = s.pos = twkb;
655  s.twkb_end = twkb + twkb_size;
656  s.check = check;
657  s.coords = coords;
658 
659  /* Handle the check catch-all values */
660  if ( check & LW_PARSER_CHECK_NONE )
661  s.check = 0;
662  else
663  s.check = check;
664 
665 
666  /* Read the rest of the geometry */
667  return lwgeom_from_twkb_state(&s);
668 }
uint32_t check
Definition: lwin_twkb.c:29
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
uint8_t * pos
Definition: lwin_twkb.c:27
uint8_t * twkb_end
Definition: lwin_twkb.c:26
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1869
#define TWKB_IN_MAXCOORDS
Definition: lwin_twkb.c:17
int64_t * coords
Definition: lwin_twkb.c:51
char * s
Definition: cu_in_wkt.c:23
Used for passing the parse state between the parsing functions.
Definition: lwin_twkb.c:22
LWGEOM * lwgeom_from_twkb_state(twkb_parse_state *s)
Internal function declarations.
Definition: lwin_twkb.c:548
uint8_t * twkb
Definition: lwin_twkb.c:25
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
Here is the call graph for this function:
Here is the caller graph for this function: