Detect corrupted chunks and reset the parser
MODIFY
src/reader_struct.cpp
src/reader_struct.cpp
@@ -73,12 +73,20 @@ void Struct<S>::ReadLcf(S& obj, LcfReader& stream) {
#ifdef LCF_DEBUG_TRACE
printf("0x%02x (size: %d, pos: 0x%x): %s\n", chunk_info.ID, chunk_info.length, stream.Tell(), it->second->name);
#endif
+ const auto off = stream.Tell();
it->second->ReadLcf(obj, stream, chunk_info.length);
+ const auto bytes_read = stream.Tell() - off;
+ if (bytes_read != chunk_info.length) {
+ fprintf(stderr, "Warning: Corrupted Chunk 0x%02x (size: %d, pos: 0x%x): %s : Read %d bytes! Reseting...\n",
+ chunk_info.ID, chunk_info.length, off, it->second->name, bytes_read);
+ stream.Seek(off + chunk_info.length);
}
- else
+ }
+ else {
stream.Skip(chunk_info);
}
}
+}
template<typename T>
typename std::enable_if<std::is_same<T, RPG::Save>::value ||

Detect corrupted chunks and reset the parser