Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Taudul <wolf.pld@gmail.com>2018-04-21 15:53:40 +0300
committerBartosz Taudul <wolf.pld@gmail.com>2018-04-21 15:53:40 +0300
commit764792d8db77b84ecbd981d71e8c5fa1d808d801 (patch)
treebea28d84f7b3327161850874f1489066fa9474e7 /server/TracyFileRead.hpp
parenta63f21496426f808c0f629f41c0b260499f3c4b6 (diff)
Try to not crash when opening invalid files.
Tracy will now perform a number of checks when trying to read a dump file: 1. The file must have at least 4 bytes of data. 2. There should be a 4 byte header to indicate the file was saved by tracy. This is a breaking change in file format. 3. Old header-less files are still supported, but there's a new check for data validity. The first 4 bytes of file (as an uint32) must be less or equal to max LZ4 data packet size. This requires the first two bytes to be 00 00 or 00 01, which should catch most invalid files.
Diffstat (limited to 'server/TracyFileRead.hpp')
-rw-r--r--server/TracyFileRead.hpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/server/TracyFileRead.hpp b/server/TracyFileRead.hpp
index 45451b34..fb851167 100644
--- a/server/TracyFileRead.hpp
+++ b/server/TracyFileRead.hpp
@@ -2,15 +2,19 @@
#define __TRACYFILEREAD_HPP__
#include <algorithm>
+#include <stdexcept>
#include <stdio.h>
#include <string.h>
+#include "TracyFileHeader.hpp"
#include "../common/tracy_lz4.hpp"
#include "../common/TracyForceInline.hpp"
namespace tracy
{
+struct NotTracyDump : public std::exception {};
+
class FileRead
{
public:
@@ -84,7 +88,18 @@ private:
, m_offset( BufSize )
, m_active( 1 )
, m_lastBlock( 0 )
- {}
+ {
+ char hdr[4];
+ if( fread( hdr, 1, sizeof( hdr ), m_file ) != sizeof( hdr ) ) throw NotTracyDump();
+ if( memcmp( hdr, Lz4Header, sizeof( hdr ) ) != 0 )
+ {
+ fseek( m_file, 0, SEEK_SET );
+ uint32_t sz;
+ static_assert( sizeof( sz ) == sizeof( hdr ), "Size mismatch" );
+ memcpy( &sz, hdr, sizeof( sz ) );
+ if( sz > LZ4Size ) throw NotTracyDump();
+ }
+ }
tracy_force_inline void ReadSmall( void* ptr, size_t size )
{