Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
77951dd7
Commit
77951dd7
authored
Oct 25, 2022
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-26161 crash in Gis_point::calculate_haversine
More checks for bad geometry data added.
parent
e910dff8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
13 deletions
+33
-13
mysql-test/main/gis.result
mysql-test/main/gis.result
+4
-0
mysql-test/main/gis.test
mysql-test/main/gis.test
+4
-0
sql/item_geofunc.cc
sql/item_geofunc.cc
+2
-2
sql/spatial.cc
sql/spatial.cc
+21
-11
sql/spatial.h
sql/spatial.h
+2
-0
No files found.
mysql-test/main/gis.result
View file @
77951dd7
...
@@ -4981,6 +4981,10 @@ ERROR HY000: Illegal parameter data type geometry for operation 'is_used_lock'
...
@@ -4981,6 +4981,10 @@ ERROR HY000: Illegal parameter data type geometry for operation 'is_used_lock'
#
#
select st_distance_sphere(x'01030000000400000004000000000000', multipoint(point(124,204)), 10);
select st_distance_sphere(x'01030000000400000004000000000000', multipoint(point(124,204)), 10);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
select st_distance_sphere(x'010300000004000000040000', multipoint(point(124,204)), 10);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
select st_distance_sphere(x'010300000001000000040000', multipoint(point(124,204)), 10);
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
#
#
# End of 10.3 tests
# End of 10.3 tests
#
#
mysql-test/main/gis.test
View file @
77951dd7
...
@@ -3095,6 +3095,10 @@ SELECT IS_USED_LOCK(POINT(1,1));
...
@@ -3095,6 +3095,10 @@ SELECT IS_USED_LOCK(POINT(1,1));
--
echo
#
--
echo
#
--
error
ER_CANT_CREATE_GEOMETRY_OBJECT
--
error
ER_CANT_CREATE_GEOMETRY_OBJECT
select
st_distance_sphere
(
x
'01030000000400000004000000000000'
,
multipoint
(
point
(
124
,
204
)),
10
);
select
st_distance_sphere
(
x
'01030000000400000004000000000000'
,
multipoint
(
point
(
124
,
204
)),
10
);
--
error
ER_CANT_CREATE_GEOMETRY_OBJECT
select
st_distance_sphere
(
x
'010300000004000000040000'
,
multipoint
(
point
(
124
,
204
)),
10
);
--
error
ER_CANT_CREATE_GEOMETRY_OBJECT
select
st_distance_sphere
(
x
'010300000001000000040000'
,
multipoint
(
point
(
124
,
204
)),
10
);
--
echo
#
--
echo
#
--
echo
# End of 10.3 tests
--
echo
# End of 10.3 tests
...
...
sql/item_geofunc.cc
View file @
77951dd7
...
@@ -2656,13 +2656,13 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
...
@@ -2656,13 +2656,13 @@ double Item_func_sphere_distance::spherical_distance_points(Geometry *g1,
break
;
break
;
}
}
if
(
err_hv
>
0
)
if
(
err_hv
==
1
)
my_error
(
ER_STD_OUT_OF_RANGE_ERROR
,
MYF
(
0
),
my_error
(
ER_STD_OUT_OF_RANGE_ERROR
,
MYF
(
0
),
"Longitude should be [-180,180]"
,
"ST_Distance_Sphere"
);
"Longitude should be [-180,180]"
,
"ST_Distance_Sphere"
);
else
if
(
err_hv
<
0
)
else
if
(
err_hv
<
0
)
my_error
(
ER_STD_OUT_OF_RANGE_ERROR
,
MYF
(
0
),
my_error
(
ER_STD_OUT_OF_RANGE_ERROR
,
MYF
(
0
),
"Latitude should be [-90,90]"
,
"ST_Distance_Sphere"
);
"Latitude should be [-90,90]"
,
"ST_Distance_Sphere"
);
else
if
(
err_sph
)
else
if
(
err_sph
||
err_hv
==
2
)
my_error
(
ER_CANT_CREATE_GEOMETRY_OBJECT
,
MYF
(
0
));
my_error
(
ER_CANT_CREATE_GEOMETRY_OBJECT
,
MYF
(
0
));
return
res
;
return
res
;
}
}
...
...
sql/spatial.cc
View file @
77951dd7
...
@@ -1071,10 +1071,9 @@ double Gis_point::calculate_haversine(const Geometry *g,
...
@@ -1071,10 +1071,9 @@ double Gis_point::calculate_haversine(const Geometry *g,
point_temp
[
point_size
-
1
]
=
'\0'
;
point_temp
[
point_size
-
1
]
=
'\0'
;
Geometry_buffer
gbuff
;
Geometry_buffer
gbuff
;
Geometry
*
gg
=
Geometry
::
construct
(
&
gbuff
,
point_temp
,
point_size
-
1
);
Geometry
*
gg
=
Geometry
::
construct
(
&
gbuff
,
point_temp
,
point_size
-
1
);
DBUG_ASSERT
(
gg
);
if
(
!
gg
||
static_cast
<
Gis_point
*>
(
gg
)
->
get_xy_radian
(
&
x2r
,
&
y2r
))
if
(
static_cast
<
Gis_point
*>
(
gg
)
->
get_xy_radian
(
&
x2r
,
&
y2r
))
{
{
DBUG_ASSERT
(
0
)
;
*
error
=
2
;
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -1082,15 +1081,16 @@ double Gis_point::calculate_haversine(const Geometry *g,
...
@@ -1082,15 +1081,16 @@ double Gis_point::calculate_haversine(const Geometry *g,
{
{
if
(
static_cast
<
const
Gis_point
*>
(
g
)
->
get_xy_radian
(
&
x2r
,
&
y2r
))
if
(
static_cast
<
const
Gis_point
*>
(
g
)
->
get_xy_radian
(
&
x2r
,
&
y2r
))
{
{
DBUG_ASSERT
(
0
)
;
*
error
=
2
;
return
-
1
;
return
-
1
;
}
}
}
}
if
(
this
->
get_xy_radian
(
&
x1r
,
&
y1r
))
if
(
this
->
get_xy_radian
(
&
x1r
,
&
y1r
))
{
{
DBUG_ASSERT
(
0
)
;
*
error
=
2
;
return
-
1
;
return
-
1
;
}
}
//
// Check boundary conditions: longitude[-180,180]
// Check boundary conditions: longitude[-180,180]
if
(
!
((
x2r
>=
-
M_PI
&&
x2r
<=
M_PI
)
&&
(
x1r
>=
-
M_PI
&&
x1r
<=
M_PI
)))
if
(
!
((
x2r
>=
-
M_PI
&&
x2r
<=
M_PI
)
&&
(
x1r
>=
-
M_PI
&&
x1r
<=
M_PI
)))
{
{
...
@@ -1143,12 +1143,16 @@ int Gis_point::spherical_distance_multipoints(Geometry *g, const double r,
...
@@ -1143,12 +1143,16 @@ int Gis_point::spherical_distance_multipoints(Geometry *g, const double r,
{
{
Geometry_buffer
buff_temp
;
Geometry_buffer
buff_temp
;
Geometry
*
temp
;
Geometry
*
temp
;
const
char
*
pt_ptr
=
g
->
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
i
+
POINT_DATA_SIZE
*
(
i
-
1
);
// First 4 bytes are handled already, make sure to create a Point
// First 4 bytes are handled already, make sure to create a Point
memset
(
s
+
4
,
Geometry
::
wkb_point
,
1
);
memset
(
s
+
4
,
Geometry
::
wkb_point
,
1
);
if
(
g
->
no_data
(
pt_ptr
,
POINT_DATA_SIZE
))
return
1
;
memcpy
(
s
+
5
,
g
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s
+
5
,
g
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s
+
4
+
WKB_HEADER_SIZE
,
g
->
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
i
+
\
memcpy
(
s
+
4
+
WKB_HEADER_SIZE
,
pt_ptr
,
POINT_DATA_SIZE
);
POINT_DATA_SIZE
*
(
i
-
1
),
POINT_DATA_SIZE
);
s
[
len
-
1
]
=
'\0'
;
s
[
len
-
1
]
=
'\0'
;
temp
=
Geometry
::
construct
(
&
buff_temp
,
s
,
len
);
temp
=
Geometry
::
construct
(
&
buff_temp
,
s
,
len
);
if
(
!
temp
)
if
(
!
temp
)
...
@@ -2329,11 +2333,14 @@ int Gis_multi_point::spherical_distance_multipoints(Geometry *g, const double r,
...
@@ -2329,11 +2333,14 @@ int Gis_multi_point::spherical_distance_multipoints(Geometry *g, const double r,
Geometry
*
temp
;
Geometry
*
temp
;
double
temp_res
=
0.0
;
double
temp_res
=
0.0
;
char
s
[
len
];
char
s
[
len
];
const
char
*
pt_ptr
=
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
i
+
POINT_DATA_SIZE
*
(
i
-
1
);
// First 4 bytes are handled already, make sure to create a Point
// First 4 bytes are handled already, make sure to create a Point
memset
(
s
+
4
,
Geometry
::
wkb_point
,
1
);
memset
(
s
+
4
,
Geometry
::
wkb_point
,
1
);
if
(
no_data
(
pt_ptr
,
POINT_DATA_SIZE
))
return
1
;
memcpy
(
s
+
5
,
this
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s
+
5
,
this
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s
+
4
+
WKB_HEADER_SIZE
,
this
->
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
i
+
\
memcpy
(
s
+
4
+
WKB_HEADER_SIZE
,
pt_ptr
,
POINT_DATA_SIZE
);
POINT_DATA_SIZE
*
(
i
-
1
),
POINT_DATA_SIZE
);
s
[
len
-
1
]
=
'\0'
;
s
[
len
-
1
]
=
'\0'
;
temp
=
Geometry
::
construct
(
&
buff_temp
,
s
,
len
);
temp
=
Geometry
::
construct
(
&
buff_temp
,
s
,
len
);
if
(
!
temp
)
if
(
!
temp
)
...
@@ -2349,11 +2356,14 @@ int Gis_multi_point::spherical_distance_multipoints(Geometry *g, const double r,
...
@@ -2349,11 +2356,14 @@ int Gis_multi_point::spherical_distance_multipoints(Geometry *g, const double r,
Geometry_buffer
buff_temp2
;
Geometry_buffer
buff_temp2
;
Geometry
*
temp2
;
Geometry
*
temp2
;
char
s2
[
len
];
char
s2
[
len
];
const
char
*
pt_ptr
=
g
->
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
j
+
POINT_DATA_SIZE
*
(
j
-
1
);
// First 4 bytes are handled already, make sure to create a Point
// First 4 bytes are handled already, make sure to create a Point
memset
(
s2
+
4
,
Geometry
::
wkb_point
,
1
);
memset
(
s2
+
4
,
Geometry
::
wkb_point
,
1
);
if
(
g
->
no_data
(
pt_ptr
,
POINT_DATA_SIZE
))
return
1
;
memcpy
(
s2
+
5
,
g
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s2
+
5
,
g
->
get_data_ptr
()
+
5
,
4
);
memcpy
(
s2
+
4
+
WKB_HEADER_SIZE
,
g
->
get_data_ptr
()
+
4
+
WKB_HEADER_SIZE
*
j
+
\
memcpy
(
s2
+
4
+
WKB_HEADER_SIZE
,
pt_ptr
,
POINT_DATA_SIZE
);
POINT_DATA_SIZE
*
(
j
-
1
),
POINT_DATA_SIZE
);
s2
[
len
-
1
]
=
'\0'
;
s2
[
len
-
1
]
=
'\0'
;
temp2
=
Geometry
::
construct
(
&
buff_temp2
,
s2
,
len
);
temp2
=
Geometry
::
construct
(
&
buff_temp2
,
s2
,
len
);
if
(
!
temp2
)
if
(
!
temp2
)
...
...
sql/spatial.h
View file @
77951dd7
...
@@ -354,6 +354,7 @@ class Geometry
...
@@ -354,6 +354,7 @@ class Geometry
const
char
*
get_mbr_for_points
(
MBR
*
mbr
,
const
char
*
data
,
uint
offset
)
const
char
*
get_mbr_for_points
(
MBR
*
mbr
,
const
char
*
data
,
uint
offset
)
const
;
const
;
public:
/**
/**
Check if there're enough data remaining as requested
Check if there're enough data remaining as requested
...
@@ -384,6 +385,7 @@ class Geometry
...
@@ -384,6 +385,7 @@ class Geometry
(
expected_points
>
((
m_data_end
-
data
)
/
(
expected_points
>
((
m_data_end
-
data
)
/
(
POINT_DATA_SIZE
+
extra_point_space
))));
(
POINT_DATA_SIZE
+
extra_point_space
))));
}
}
protected:
const
char
*
m_data
;
const
char
*
m_data
;
const
char
*
m_data_end
;
const
char
*
m_data_end
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment