Skip to content

Commit

Permalink
Merge pull request #4266 from rouault/fix_ci_fuzz_pr_4265
Browse files Browse the repository at this point in the history
WKT importer: fix nullptr dereference on invalid VERTCS[]
  • Loading branch information
rouault authored Oct 5, 2024
2 parents 702847d + e3b6bb2 commit 4659ad1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4786,14 +4786,15 @@ VerticalReferenceFrameNNPtr WKTParser::Private::buildVerticalReferenceFrame(
const auto *nodeP = node->GP();
const std::string &name(nodeP->value());
auto &props = buildProperties(node);
const auto &children = nodeP->children();

if (esriStyle_ && dbContext_) {
if (esriStyle_ && dbContext_ && !children.empty()) {
std::string outTableName;
std::string authNameFromAlias;
std::string codeFromAlias;
auto authFactory =
AuthorityFactory::create(NN_NO_CHECK(dbContext_), std::string());
const std::string datumName = stripQuotes(nodeP->children()[0]);
const std::string datumName = stripQuotes(children[0]);
auto officialName = authFactory->getOfficialNameFromAlias(
datumName, "vertical_datum", "ESRI", false, outTableName,
authNameFromAlias, codeFromAlias);
Expand All @@ -4803,7 +4804,6 @@ VerticalReferenceFrameNNPtr WKTParser::Private::buildVerticalReferenceFrame(
}

if (ci_equal(name, WKTConstants::VERT_DATUM)) {
const auto &children = nodeP->children();
if (children.size() >= 2) {
props.set("VERT_DATUM_TYPE", children[1]->GP()->value());
}
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8877,6 +8877,22 @@ TEST(wkt_parse, invalid_VERTCRS) {

// ---------------------------------------------------------------------------

TEST(wkt_parse, invalid_esri_VERTCS) {

// VDATUM without child
EXPECT_THROW(WKTParser().createFromWKT(
"GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\","
"SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],"
"PRIMEM[\"Greenwich\",0.0],"
"UNIT[\"Degree\",0.0174532925199433]],"
"VERTCS[\"EGM96_Geoid\",VDATUM,"
"PARAMETER[\"Vertical_Shift\",0.0],"
"PARAMETER[\"Direction\",1.0],UNIT[\"Meter\",1.0]]"),
ParsingException);
}

// ---------------------------------------------------------------------------

TEST(wkt_parse, invalid_VERT_CS) {

EXPECT_NO_THROW(WKTParser().createFromWKT(
Expand Down

0 comments on commit 4659ad1

Please sign in to comment.