From 1674558dbb1165954b06eeee4fffb5a69506a3cb Mon Sep 17 00:00:00 2001 From: Rainer Clasen Date: Mon, 25 Jul 2011 18:01:49 +0200 Subject: [PATCH] FitRideFile: turned assertions into graceful fail reading Fit files with Smart recording and a certain pattern of timestamps could cause assertions. This shouldn't happen, as it's no Programming error. Changed the checks into graceful failures. Unfortunatly I don't have any files to test this. fixes #364 --- src/FitRideFile.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/FitRideFile.cpp b/src/FitRideFile.cpp index 27ddecfd9..69ec8b971 100644 --- a/src/FitRideFile.cpp +++ b/src/FitRideFile.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -78,6 +77,7 @@ struct FitFileReaderState } struct TruncatedRead {}; + struct BadDelta {}; void read_unknown( int size, int *count = NULL ){ char c[size+1]; @@ -388,9 +388,11 @@ struct FitFileReaderState // Evil smart recording. Linearly interpolate missing points. RideFilePoint *prevPoint = rideFile->dataPoints().back(); int deltaSecs = (int) (secs - prevPoint->secs); - assert(deltaSecs == secs - prevPoint->secs); // no fractional part + if(deltaSecs != secs - prevPoint->secs) + throw BadDelta(); // no fractional part // This is only true if the previous record was of type record: - assert(deltaSecs == time - last_time); + if(deltaSecs != time - last_time) + throw BadDelta(); // If the last lat/lng was missing (0/0) then all points up to lat/lng are marked as 0/0. if (prevPoint->lat == 0 && prevPoint->lon == 0 ) { badgps = 1; @@ -571,6 +573,11 @@ struct FitFileReaderState delete rideFile; return NULL; } + catch (BadDelta &e) { + errors << "Unsupported smart recording interval found"; + delete rideFile; + return NULL; + } if (stop) { delete rideFile; return NULL;