|
|
|
@ -394,18 +394,19 @@ const char *Geometry::append_points(String *txt, uint32 n_points, |
|
|
|
const char *Geometry::get_mbr_for_points(MBR *mbr, const char *data, |
|
|
|
uint offset) const |
|
|
|
{ |
|
|
|
uint32 points; |
|
|
|
uint32 n_points; |
|
|
|
/* read number of points */ |
|
|
|
if (no_data(data, 4)) |
|
|
|
return 0; |
|
|
|
points= uint4korr(data); |
|
|
|
n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
|
|
|
|
if (no_data(data, (SIZEOF_STORED_DOUBLE * 2 + offset) * points)) |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(data, (POINT_DATA_SIZE + offset) * n_points)) |
|
|
|
return 0; |
|
|
|
|
|
|
|
/* Calculate MBR for points */ |
|
|
|
while (points--) |
|
|
|
while (n_points--) |
|
|
|
{ |
|
|
|
data+= offset; |
|
|
|
mbr->add_xy(data, data + SIZEOF_STORED_DOUBLE); |
|
|
|
@ -484,9 +485,12 @@ const Geometry::Class_info *Gis_point::get_class_info() const |
|
|
|
|
|
|
|
uint32 Gis_line_string::get_data_size() const |
|
|
|
{ |
|
|
|
if (no_data(m_data, 4)) |
|
|
|
uint32 n_points, size; |
|
|
|
if (no_data(m_data, 4) || |
|
|
|
(n_points= uint4korr(m_data)) > max_n_points || |
|
|
|
no_data(m_data, (size= 4 + n_points * POINT_DATA_SIZE))) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return 4 + uint4korr(m_data) * POINT_DATA_SIZE; |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -556,7 +560,7 @@ bool Gis_line_string::get_data_as_wkt(String *txt, const char **end) const |
|
|
|
n_points= uint4korr(data); |
|
|
|
data += 4; |
|
|
|
|
|
|
|
if (n_points < 1 || |
|
|
|
if (n_points < 1 || n_points > max_n_points || |
|
|
|
no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points) || |
|
|
|
txt->reserve(((MAX_DIGITS_IN_DOUBLE + 1)*2 + 1) * n_points)) |
|
|
|
return 1; |
|
|
|
@ -594,7 +598,8 @@ int Gis_line_string::geom_length(double *len) const |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
if (n_points < 1 || no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) |
|
|
|
if (n_points < 1 || n_points > max_n_points || |
|
|
|
no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) |
|
|
|
return 1; |
|
|
|
|
|
|
|
get_point(&prev_x, &prev_y, data); |
|
|
|
@ -628,7 +633,7 @@ int Gis_line_string::is_closed(int *closed) const |
|
|
|
return 0; |
|
|
|
} |
|
|
|
data+= 4; |
|
|
|
if (n_points == 0 || |
|
|
|
if (n_points == 0 || n_points > max_n_points || |
|
|
|
no_data(data, SIZEOF_STORED_DOUBLE * 2 * n_points)) |
|
|
|
return 1; |
|
|
|
|
|
|
|
@ -664,6 +669,9 @@ int Gis_line_string::end_point(String *result) const |
|
|
|
if (no_data(m_data, 4)) |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(m_data); |
|
|
|
if (n_points == 0 || n_points > max_n_points || |
|
|
|
no_data(m_data, POINT_DATA_SIZE * n_points)) |
|
|
|
return 1; |
|
|
|
return create_point(result, m_data + 4 + (n_points - 1) * POINT_DATA_SIZE); |
|
|
|
} |
|
|
|
|
|
|
|
@ -673,11 +681,14 @@ int Gis_line_string::point_n(uint32 num, String *result) const |
|
|
|
uint32 n_points; |
|
|
|
if (no_data(m_data, 4)) |
|
|
|
return 1; |
|
|
|
num--; |
|
|
|
n_points= uint4korr(m_data); |
|
|
|
if ((uint32) (num - 1) >= n_points) // means (num > n_points || num < 1)
|
|
|
|
if (num >= n_points || |
|
|
|
num > max_n_points || // means (num > n_points || num < 1)
|
|
|
|
no_data(m_data, num * POINT_DATA_SIZE)) |
|
|
|
return 1; |
|
|
|
|
|
|
|
return create_point(result, m_data + 4 + (num - 1) * POINT_DATA_SIZE); |
|
|
|
return create_point(result, m_data + 4 + num*POINT_DATA_SIZE); |
|
|
|
} |
|
|
|
|
|
|
|
const Geometry::Class_info *Gis_line_string::get_class_info() const |
|
|
|
@ -691,6 +702,7 @@ const Geometry::Class_info *Gis_line_string::get_class_info() const |
|
|
|
uint32 Gis_polygon::get_data_size() const |
|
|
|
{ |
|
|
|
uint32 n_linear_rings; |
|
|
|
uint32 n_points; |
|
|
|
const char *data= m_data; |
|
|
|
|
|
|
|
if (no_data(data, 4)) |
|
|
|
@ -700,10 +712,13 @@ uint32 Gis_polygon::get_data_size() const |
|
|
|
|
|
|
|
while (n_linear_rings--) |
|
|
|
{ |
|
|
|
if (no_data(data, 4)) |
|
|
|
if (no_data(data, 4) || |
|
|
|
(n_points= uint4korr(data)) > max_n_points) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
data+= 4 + uint4korr(data)*POINT_DATA_SIZE; |
|
|
|
data+= 4 + n_points*POINT_DATA_SIZE; |
|
|
|
} |
|
|
|
if (no_data(data, 0)) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return (uint32) (data - m_data); |
|
|
|
} |
|
|
|
|
|
|
|
@ -798,7 +813,8 @@ bool Gis_polygon::get_data_as_wkt(String *txt, const char **end) const |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
if (no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points) || |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points) || |
|
|
|
txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1) * 2 + 1) * n_points)) |
|
|
|
return 1; |
|
|
|
txt->qs_append('('); |
|
|
|
@ -852,7 +868,8 @@ int Gis_polygon::area(double *ar, const char **end_of_data) const |
|
|
|
if (no_data(data, 4)) |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data); |
|
|
|
if (no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points)) |
|
|
|
if (n_points == 0 || n_points > max_n_points || |
|
|
|
no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points)) |
|
|
|
return 1; |
|
|
|
get_point(&prev_x, &prev_y, data+4); |
|
|
|
data+= (4+SIZEOF_STORED_DOUBLE*2); |
|
|
|
@ -888,7 +905,8 @@ int Gis_polygon::exterior_ring(String *result) const |
|
|
|
n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
length= n_points * POINT_DATA_SIZE; |
|
|
|
if (no_data(data, length) || result->reserve(1+4+4+ length)) |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(data, length) || result->reserve(1+4+4+ length)) |
|
|
|
return 1; |
|
|
|
|
|
|
|
result->q_append((char) wkb_ndr); |
|
|
|
@ -954,13 +972,11 @@ int Gis_polygon::centroid_xy(double *x, double *y) const |
|
|
|
const char *data= m_data; |
|
|
|
bool first_loop= 1; |
|
|
|
|
|
|
|
if (no_data(data, 4)) |
|
|
|
if (no_data(data, 4) || |
|
|
|
(n_linear_rings= uint4korr(data)) == 0) |
|
|
|
return 1; |
|
|
|
n_linear_rings= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
|
|
|
|
DBUG_ASSERT(n_linear_rings > 0); |
|
|
|
|
|
|
|
while (n_linear_rings--) |
|
|
|
{ |
|
|
|
uint32 n_points, org_n_points; |
|
|
|
@ -973,7 +989,8 @@ int Gis_polygon::centroid_xy(double *x, double *y) const |
|
|
|
return 1; |
|
|
|
org_n_points= n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
if (no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points)) |
|
|
|
if (n_points == 0 || n_points > max_n_points || |
|
|
|
no_data(data, (SIZEOF_STORED_DOUBLE*2) * n_points)) |
|
|
|
return 1; |
|
|
|
get_point(&prev_x, &prev_y, data); |
|
|
|
data+= (SIZEOF_STORED_DOUBLE*2); |
|
|
|
@ -1032,9 +1049,14 @@ const Geometry::Class_info *Gis_polygon::get_class_info() const |
|
|
|
|
|
|
|
uint32 Gis_multi_point::get_data_size() const |
|
|
|
{ |
|
|
|
if (no_data(m_data, 4)) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return 4 + uint4korr(m_data)*(POINT_DATA_SIZE + WKB_HEADER_SIZE); |
|
|
|
uint32 n_points; |
|
|
|
uint32 size; |
|
|
|
|
|
|
|
if (no_data(m_data, 4) || |
|
|
|
(n_points= uint4korr(m_data)) > max_n_points || |
|
|
|
no_data(m_data, (size= 4 + n_points*(POINT_DATA_SIZE + WKB_HEADER_SIZE)))) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1102,7 +1124,8 @@ bool Gis_multi_point::get_data_as_wkt(String *txt, const char **end) const |
|
|
|
return 1; |
|
|
|
|
|
|
|
n_points= uint4korr(m_data); |
|
|
|
if (no_data(m_data+4, |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(m_data+4, |
|
|
|
n_points * (SIZEOF_STORED_DOUBLE * 2 + WKB_HEADER_SIZE)) || |
|
|
|
txt->reserve(((MAX_DIGITS_IN_DOUBLE + 1) * 2 + 1) * n_points)) |
|
|
|
return 1; |
|
|
|
@ -1155,6 +1178,7 @@ const Geometry::Class_info *Gis_multi_point::get_class_info() const |
|
|
|
uint32 Gis_multi_line_string::get_data_size() const |
|
|
|
{ |
|
|
|
uint32 n_line_strings; |
|
|
|
uint32 n_points; |
|
|
|
const char *data= m_data; |
|
|
|
|
|
|
|
if (no_data(data, 4)) |
|
|
|
@ -1164,11 +1188,13 @@ uint32 Gis_multi_line_string::get_data_size() const |
|
|
|
|
|
|
|
while (n_line_strings--) |
|
|
|
{ |
|
|
|
if (no_data(data, WKB_HEADER_SIZE + 4)) |
|
|
|
if (no_data(data, WKB_HEADER_SIZE + 4) || |
|
|
|
(n_points= uint4korr(data + WKB_HEADER_SIZE)) > max_n_points) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
data+= (WKB_HEADER_SIZE + 4 + uint4korr(data + WKB_HEADER_SIZE) * |
|
|
|
POINT_DATA_SIZE); |
|
|
|
data+= (WKB_HEADER_SIZE + 4 + n_points*POINT_DATA_SIZE); |
|
|
|
} |
|
|
|
if (no_data(data, 0)) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return (uint32) (data - m_data); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1260,7 +1286,8 @@ bool Gis_multi_line_string::get_data_as_wkt(String *txt, |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data + WKB_HEADER_SIZE); |
|
|
|
data+= WKB_HEADER_SIZE + 4; |
|
|
|
if (no_data(data, n_points * (SIZEOF_STORED_DOUBLE*2)) || |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(data, n_points * (SIZEOF_STORED_DOUBLE*2)) || |
|
|
|
txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1) * 2 + 1) * n_points)) |
|
|
|
return 1; |
|
|
|
txt->qs_append('('); |
|
|
|
@ -1321,7 +1348,7 @@ int Gis_multi_line_string::geometry_n(uint32 num, String *result) const |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data + WKB_HEADER_SIZE); |
|
|
|
length= WKB_HEADER_SIZE + 4+ POINT_DATA_SIZE * n_points; |
|
|
|
if (no_data(data, length)) |
|
|
|
if (n_points > max_n_points || no_data(data, length)) |
|
|
|
return 1; |
|
|
|
if (!--num) |
|
|
|
break; |
|
|
|
@ -1401,6 +1428,7 @@ const Geometry::Class_info *Gis_multi_line_string::get_class_info() const |
|
|
|
uint32 Gis_multi_polygon::get_data_size() const |
|
|
|
{ |
|
|
|
uint32 n_polygons; |
|
|
|
uint32 n_points; |
|
|
|
const char *data= m_data; |
|
|
|
|
|
|
|
if (no_data(data, 4)) |
|
|
|
@ -1419,11 +1447,14 @@ uint32 Gis_multi_polygon::get_data_size() const |
|
|
|
|
|
|
|
while (n_linear_rings--) |
|
|
|
{ |
|
|
|
if (no_data(data, 4)) |
|
|
|
if (no_data(data, 4) || |
|
|
|
(n_points= uint4korr(data)) > max_n_points) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
data+= 4 + uint4korr(data) * POINT_DATA_SIZE; |
|
|
|
data+= 4 + n_points * POINT_DATA_SIZE; |
|
|
|
} |
|
|
|
} |
|
|
|
if (no_data(data, 0)) |
|
|
|
return GET_SIZE_ERROR; |
|
|
|
return (uint32) (data - m_data); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1521,7 +1552,8 @@ bool Gis_multi_polygon::get_data_as_wkt(String *txt, const char **end) const |
|
|
|
return 1; |
|
|
|
uint32 n_points= uint4korr(data); |
|
|
|
data+= 4; |
|
|
|
if (no_data(data, (SIZEOF_STORED_DOUBLE * 2) * n_points) || |
|
|
|
if (n_points > max_n_points || |
|
|
|
no_data(data, (SIZEOF_STORED_DOUBLE * 2) * n_points) || |
|
|
|
txt->reserve(2 + ((MAX_DIGITS_IN_DOUBLE + 1) * 2 + 1) * n_points, |
|
|
|
512)) |
|
|
|
return 1; |
|
|
|
@ -1604,6 +1636,8 @@ int Gis_multi_polygon::geometry_n(uint32 num, String *result) const |
|
|
|
if (no_data(data, 4)) |
|
|
|
return 1; |
|
|
|
n_points= uint4korr(data); |
|
|
|
if (n_points > max_n_points) |
|
|
|
return 1; |
|
|
|
data+= 4 + POINT_DATA_SIZE * n_points; |
|
|
|
} |
|
|
|
} while (--num); |
|
|
|
|