mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-17 16:20:48 +01:00
Do not load into memory files that are definitely not JSON files
This commit is contained in:
parent
15bc9ac774
commit
4f661128ba
@ -104,6 +104,26 @@ static void setWaypointProperties(Waypoint &waypoint,
|
|||||||
waypoint.setStyle(PointStyle(color, size));
|
waypoint.setStyle(PointStyle(color, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isWS(char c)
|
||||||
|
{
|
||||||
|
return (c == 0x20 || c == 0x09 || c == 0x0A || c == 0x0D) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isJSONObject(QFile *file)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while (file->getChar(&c)) {
|
||||||
|
if (isWS(c))
|
||||||
|
continue;
|
||||||
|
else if (c == '{')
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
GeoJSONParser::Type GeoJSONParser::type(const QJsonObject &json)
|
GeoJSONParser::Type GeoJSONParser::type(const QJsonObject &json)
|
||||||
{
|
{
|
||||||
@ -404,6 +424,13 @@ bool GeoJSONParser::parse(QFile *file, QList<TrackData> &tracks,
|
|||||||
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
|
QList<RouteData> &routes, QList<Area> &areas, QVector<Waypoint> &waypoints)
|
||||||
{
|
{
|
||||||
Q_UNUSED(routes);
|
Q_UNUSED(routes);
|
||||||
|
|
||||||
|
if (!isJSONObject(file)) {
|
||||||
|
_errorString = "Not a GeoJSON file";
|
||||||
|
return false;
|
||||||
|
} else
|
||||||
|
file->reset();
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc(QJsonDocument::fromJson(file->readAll(), &error));
|
QJsonDocument doc(QJsonDocument::fromJson(file->readAll(), &error));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user