Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion::createUTM(): avoid integer overflow #2795

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/create_c_api_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ def snake_casify(s):
test_cppfile.write("{\n")
test_cppfile.write(" auto projCRS = proj_create_conversion_" + c_shortName + "(\n")
test_cppfile.write(" m_ctxt")
for param in params:
test_cppfile.write(", 0")
if c_shortName == 'utm':
test_cppfile.write(", 1")
else:
for param in params:
test_cppfile.write(", 0")
if has_angle:
test_cppfile.write(", \"Degree\", 0.0174532925199433")
if has_linear:
Expand All @@ -184,4 +187,4 @@ def snake_casify(s):

test_cppfile.write("/* END: Generated by scripts/create_c_api_projections.py*/\n")

print('projections.h and .cpp, and test_projections.cpp have been generated. Manually merge them now')
print('projections.h and .cpp, and test_projections.cpp have been generated. Manually merge them now')
3 changes: 3 additions & 0 deletions src/iso19111/operation/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ Conversion::create(const util::PropertyMap &properties,
*/
ConversionNNPtr Conversion::createUTM(const util::PropertyMap &properties,
int zone, bool north) {
if (zone < 1 || zone > 60) {
throw InvalidOperation("Invalid zone number");
}
return create(
getUTMConversionProperty(properties, zone, north),
EPSG_CODE_METHOD_TRANSVERSE_MERCATOR,
Expand Down
9 changes: 8 additions & 1 deletion test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,10 +2373,17 @@ TEST_F(CApi, check_coord_op_obj_can_be_used_with_proj_trans) {
// ---------------------------------------------------------------------------

TEST_F(CApi, proj_create_projections) {
{
constexpr int invalid_zone_number = 0;
auto projCRS =
proj_create_conversion_utm(m_ctxt, invalid_zone_number, 0);
ObjectKeeper keeper_projCRS(projCRS);
ASSERT_EQ(projCRS, nullptr);
}

/* BEGIN: Generated by scripts/create_c_api_projections.py*/
{
auto projCRS = proj_create_conversion_utm(m_ctxt, 0, 0);
auto projCRS = proj_create_conversion_utm(m_ctxt, 1, 0);
ObjectKeeper keeper_projCRS(projCRS);
ASSERT_NE(projCRS, nullptr);
}
Expand Down