Permalink
Browse files

Fix #573, on string attrs >4M use saturate instead of overflow

  • Loading branch information...
klirichek committed Jan 9, 2019
1 parent 05186f5 commit 6b95d48240d3b5520afade19c249d79e020a5e88
Showing with 13 additions and 2 deletions.
  1. +6 −1 src/searchd.cpp
  2. +1 −1 src/searchdaemon.h
  3. +6 −0 src/sphinx.cpp
@@ -13335,7 +13335,7 @@ class SphinxqlRequestBuilder_c : public IRequestBuilder_t
};


void sphHandleMysqlInsert ( StmtErrorReporter_i & tOut, const SqlStmt_t & tStmt, bool bReplace, bool bCommit, CSphString & sWarning, CSphSessionAccum & tAcc, ESphCollation eCollation )
void sphHandleMysqlInsert ( StmtErrorReporter_i & tOut, SqlStmt_t & tStmt, bool bReplace, bool bCommit, CSphString & sWarning, CSphSessionAccum & tAcc, ESphCollation eCollation )
{
MEMORY ( MEM_SQL_INSERT );

@@ -13598,6 +13598,11 @@ void sphHandleMysqlInsert ( StmtErrorReporter_i & tOut, const SqlStmt_t & tStmt,
bResult = tDoc.SetAttr ( tLoc, tVal, tCol.m_eAttrType );
if ( tCol.m_eAttrType==SPH_ATTR_STRING )
{
if ( tVal.m_sVal.Length() > 0x3FFFFF )
{
*( char * ) ( tVal.m_sVal.cstr () + 0x3FFFFF ) = '\0';
sWarning.SetSprintf ( "String column %d at row %d truncated to 0x3FFFFF chars", i, c );
}
dStrings.Add ( tVal.m_sVal.cstr() );
} else if ( tCol.m_eAttrType==SPH_ATTR_JSON )
{
@@ -1308,7 +1308,7 @@ bool CheckCommandVersion ( WORD uVer, WORD uDaemonVersion, ISphOutputBuffer & tO
ISphSearchHandler * sphCreateSearchHandler ( int iQueries, const QueryParser_i * pQueryParser, QueryType_e eQueryType, bool bMaster, const ThdDesc_t & tThd );
void sphFormatFactors ( StringBuilder_c& dOut, const unsigned int * pFactors, bool bJson );
bool sphParseSqlQuery ( const char * sQuery, int iLen, CSphVector<SqlStmt_t> & dStmt, CSphString & sError, ESphCollation eCollation );
void sphHandleMysqlInsert ( StmtErrorReporter_i & tOut, const SqlStmt_t & tStmt, bool bReplace, bool bCommit, CSphString & sWarning, CSphSessionAccum & tAcc, ESphCollation eCollation );
void sphHandleMysqlInsert ( StmtErrorReporter_i & tOut, SqlStmt_t & tStmt, bool bReplace, bool bCommit, CSphString & sWarning, CSphSessionAccum & tAcc, ESphCollation eCollation );
void sphHandleMysqlUpdate ( StmtErrorReporter_i & tOut, const QueryParserFactory_i & tQueryParserFactory, const SqlStmt_t & tStmt, const CSphString & sQuery, CSphString & sWarning, const ThdDesc_t & tThd );
void sphHandleMysqlDelete ( StmtErrorReporter_i & tOut, const QueryParserFactory_i & tQueryParserFactory, const SqlStmt_t & tStmt, const CSphString & sQuery, bool bCommit, CSphSessionAccum & tAcc, const ThdDesc_t & tThd );

@@ -11971,6 +11971,12 @@ int CSphIndex_VLN::Build ( const CSphVector<CSphSource*> & dSources, int iMemory
sData = (const char*)dBson.Begin();
iLen = dBson.GetLength();
}
// truncate string on 4M bound
else if ( strlen ( sData )>0x3FFFFF )
{
*( char * ) ( sData + 0x3FFFFF ) = '\0';
m_sLastWarning.SetSprintf ( "too long string attribute was truncated to 4M-1 chars" );
}

// calc offset, do sanity checks
SphOffset_t uOff = tStrWriter.GetPos();

0 comments on commit 6b95d48

Please sign in to comment.