File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -363,7 +363,7 @@ NodeModels SidepanelEditor::importFromXML(QFile* file)
363363
364364 if (!file->open (QIODevice::ReadOnly))
365365 {
366- QMessageBox::warning (this ," Error loading TreeNodeModel form file" ,
366+ QMessageBox::warning (this ," Error loading TreeNodeModel from file" ,
367367 " The XML was not correctly loaded" );
368368 return {};
369369 }
Original file line number Diff line number Diff line change @@ -176,8 +176,28 @@ void SidepanelReplay::on_LoadLog()
176176void SidepanelReplay::loadLog (const QByteArray &content)
177177{
178178 const char * buffer = reinterpret_cast <const char *>(content.data ());
179+
180+ // how many bytes did we read off the disk (uoffset_t aka uint32_t)
181+ const auto read_bytes = content.size ();
182+
183+ // we need at least 4 bytes to read the bt_header_size
184+ if ( read_bytes < 4 ) {
185+ QMessageBox::warning ( this , " Log file is empty" ,
186+ " Failed to load this file.\n "
187+ " This Log file is empty" );
188+ return ;
189+ }
179190
180- size_t bt_header_size = flatbuffers::ReadScalar<uint32_t >(buffer);
191+ // read the length of the header section from the file
192+ const size_t bt_header_size = flatbuffers::ReadScalar<uint32_t >(buffer);
193+
194+ // if the length of the header goes past the end of the file, it is invalid
195+ if ( (bt_header_size == 0 ) || (bt_header_size > read_bytes) ) {
196+ QMessageBox::warning ( this , " Log file is corrupt" ,
197+ " Failed to load this file.\n "
198+ " This Log file corrupted or truncated" );
199+ return ;
200+ }
181201
182202 flatbuffers::Verifier verifier ( reinterpret_cast <const uint8_t *>(buffer+4 ),
183203 size_t (content.size () -4 ));
You can’t perform that action at this time.
0 commit comments