Skip to content
Permalink
Browse files
Fix crash of wrong mmap read
Let's make mmap-reader stable out of ill-formed readers.
Real reason of such behaviour is still need to be investigated, however
let's lot crash because of it right now.
That most probably fixes #930
  • Loading branch information
klirichek committed Jun 27, 2019
1 parent 7f9de40 commit f3a8e096fd496a6b001d398aadbb781b2dbad929
Showing with 12 additions and 2 deletions.
  1. +12 −2 src/sphinx.cpp
@@ -621,6 +621,16 @@ class ThinMMapReader_c : public FileBlockReader_c
m_pPointer = m_pBase = pArena;
m_iSize = iSize;
}

BYTE GetByte()
{
auto iPos = m_pPointer - m_pBase;
if ( iPos>=0 && iPos<m_iSize )
return *m_pPointer++;
sphWarning( "INTERNAL: out-of-range in ThinMMapReader_c: trying to read at " INT64_FMT ", from mmap of "
INT64_FMT ", query most probably would FAIL; report the fact to dev!", int64_t(iPos), int64_t (m_iSize));
return 0; // it's better then crash because of unexpected read out-of-range (file reader does the same there)
}
};

class DirectFileReader_c: public FileBlockReader_c, protected FileReader_c
@@ -8338,8 +8348,8 @@ SphOffset_t sphUnzipOffset ( const BYTE * & pBuf ) { SPH_VARINT_DECODE ( SphOffs
DWORD CSphReader::UnzipInt () { SPH_VARINT_DECODE ( DWORD, GetByte() ); }
uint64_t CSphReader::UnzipOffset () { SPH_VARINT_DECODE ( uint64_t, GetByte() ); }

DWORD ThinMMapReader_c::UnzipInt () { SPH_VARINT_DECODE ( DWORD, *m_pPointer++ ); }
uint64_t ThinMMapReader_c::UnzipOffset () { SPH_VARINT_DECODE ( uint64_t, *m_pPointer++ ); }
DWORD ThinMMapReader_c::UnzipInt () { SPH_VARINT_DECODE ( DWORD, GetByte() ); }
uint64_t ThinMMapReader_c::UnzipOffset () { SPH_VARINT_DECODE ( uint64_t, GetByte() ); }

#define sphUnzipWordid sphUnzipOffset

0 comments on commit f3a8e09

Please sign in to comment.