diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2017-10-07 14:45:42 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-10-07 08:36:10 -0700 |
commit | e78f89b0d897bf479737bfca0b4c2a6d6523368f (patch) | |
tree | 5971eea73ab25acdfdeb4d7d7ed041dd0a6e1d56 | |
parent | 1b0812a8cb70a767b029daf82d9251fa7dcc0afb (diff) | |
download | subsurface-e78f89b0d897bf479737bfca0b4c2a6d6523368f.tar.gz |
Safeguards for Liquivision import
I have received one sample log where after parsing a bunch of dives
properly, the sample count hits zero, and after that it is astronomical.
In case of zero, the only data we have is dive date and time of a
duplicate dive that we already parsed with proper dive profile. So
preventing a crash with this hack without properly understanding the
weird file format.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
-rw-r--r-- | core/liquivision.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/core/liquivision.c b/core/liquivision.c index 8ed358a0f..f0762409c 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -278,6 +278,15 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int algorithm = *(buf + ptr++); // 0=ZH-L16C+GF sample_count = array_uint32_le(buf + ptr); } + + if (sample_count == 0) { + fprintf(stderr, "DEBUG: sample count 0 - terminating parser\n"); + break; + } + if (ptr + sample_count * 4 + 4 > buf_size) { + fprintf(stderr, "DEBUG: BOF - terminating parser\n"); + break; + } // we aren't using the start_cns, dive_mode, and algorithm, yet (void)start_cns; (void)dive_mode; |