From f814dc5ff9ee7f94391751336443c301c0848641 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 Jan 2022 17:06:28 -0500 Subject: [PATCH] add checks after reading data --- src/reader_native.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/reader_native.cpp b/src/reader_native.cpp index 065adb5d01..32b2279a60 100644 --- a/src/reader_native.cpp +++ b/src/reader_native.cpp @@ -142,8 +142,7 @@ void ReaderNative::skip() read_lines(2); bigint natoms; int rv = sscanf(line,BIGINT_FORMAT,&natoms); - if (rv != 1) - error->one(FLERR,"Dump file is incorrectly formatted"); + if (rv != 1) error->one(FLERR,"Dump file is incorrectly formatted"); read_lines(5); @@ -164,20 +163,17 @@ void ReaderNative::skip_reading_magic_str() if (is_known_magic_str() && revision > 0x0001) { int len; read_buf(&len, sizeof(int), 1); + if (len < 0) error->one(FLERR,"Dump file is invalid or corrupted"); - if (len > 0) { - // has units - skip_buf(sizeof(char)*len); - } + // has units + if (len > 0) skip_buf(sizeof(char)*len); char flag = 0; read_buf(&flag, sizeof(char), 1); - - if (flag) { - skip_buf(sizeof(double)); - } + if (flag) skip_buf(sizeof(double)); read_buf(&len, sizeof(int), 1); + if (len < 0) error->one(FLERR,"Dump file is invalid or corrupted"); skip_buf(sizeof(char)*len); } }