Skip to content

Commit

Permalink
Merge pull request #9138 from rouault/GDALDeserializeGCPListFromXML_v…
Browse files Browse the repository at this point in the history
…alidation

GDALDeserializeGCPListFromXML(): validate value of GCP Pixel,Line,X,Y,Z attributes
rouault authored Feb 9, 2024
2 parents a93ca97 + 4d4b7c5 commit 84b0b0b
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions gcore/gdal_misc.cpp
Original file line number Diff line number Diff line change
@@ -4202,19 +4202,51 @@ void GDALDeserializeGCPListFromXML(CPLXMLNode *psGCPList,
CPLFree(psGCP->pszInfo);
psGCP->pszInfo = CPLStrdup(CPLGetXMLValue(psXMLGCP, "Info", ""));

psGCP->dfGCPPixel = CPLAtof(CPLGetXMLValue(psXMLGCP, "Pixel", "0.0"));
psGCP->dfGCPLine = CPLAtof(CPLGetXMLValue(psXMLGCP, "Line", "0.0"));
const auto ParseDoubleValue =
[psXMLGCP](const char *pszParameter, double &dfVal)
{
const char *pszVal =
CPLGetXMLValue(psXMLGCP, pszParameter, nullptr);
if (!pszVal)
{
CPLError(CE_Failure, CPLE_AppDefined, "GCP#%s is missing",
pszParameter);
return false;
}
char *endptr = nullptr;
dfVal = CPLStrtod(pszVal, &endptr);
if (endptr == pszVal)
{
CPLError(CE_Failure, CPLE_AppDefined,
"GCP#%s=%s is an invalid value", pszParameter, pszVal);
return false;
}
return true;
};

psGCP->dfGCPX = CPLAtof(CPLGetXMLValue(psXMLGCP, "X", "0.0"));
psGCP->dfGCPY = CPLAtof(CPLGetXMLValue(psXMLGCP, "Y", "0.0"));
if (!ParseDoubleValue("Pixel", psGCP->dfGCPPixel))
continue;
if (!ParseDoubleValue("Line", psGCP->dfGCPLine))
continue;
if (!ParseDoubleValue("X", psGCP->dfGCPX))
continue;
if (!ParseDoubleValue("Y", psGCP->dfGCPY))
continue;
const char *pszZ = CPLGetXMLValue(psXMLGCP, "Z", nullptr);
if (pszZ == nullptr)
{
// Note: GDAL 1.10.1 and older generated #GCPZ,
// but could not read it back.
pszZ = CPLGetXMLValue(psXMLGCP, "GCPZ", "0.0");
}
psGCP->dfGCPZ = CPLAtof(pszZ);
char *endptr = nullptr;
psGCP->dfGCPZ = CPLStrtod(pszZ, &endptr);
if (endptr == pszZ)
{
CPLError(CE_Failure, CPLE_AppDefined,
"GCP#Z=%s is an invalid value", pszZ);
continue;
}

(*pnGCPCount)++;
}

0 comments on commit 84b0b0b

Please sign in to comment.