Skip to content

Commit

Permalink
fixed #197 indexer crash on xml embeded schema with empty attribute n…
Browse files Browse the repository at this point in the history
…ame; added regression to tests
  • Loading branch information
tomatolog committed Feb 8, 2018
1 parent a5563a4 commit 3613714
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
44 changes: 44 additions & 0 deletions src/gtests_text.cpp
Expand Up @@ -590,3 +590,47 @@ TEST ( Text, cvs_source )
} }




//////////////////////////////////////////////////////////////////////////

TEST ( Text, xml_source_attr_error )
{
const char * sTest =
R"raw(<?xml version="1.0" encoding="utf-8"?>
<sphinx:docset xmlns:sphinx="http://sphinxsearch.com/">
<sphinx:schema>
<sphinx:attr name="" type="int" />
<sphinx:field name="f" />
</sphinx:schema>
<sphinx:document id="1">
<>9</>
<f>hey</f>
</sphinx:document>
</sphinx:docset>
)raw";

const char * sRes = "source 'xml': (null) is not a valid attribute name (line=4, pos=4, docid=0)";

CSphString sTmpFile = "__libsphinxtestxml.xml";
// write xml file
FILE * fp = fopen ( sTmpFile.cstr(), "wb" );
fwrite ( sTest, 1, strlen ( sTest ), fp );
fclose ( fp );

// open csv pipe
fp = fopen ( sTmpFile.cstr(), "rb" );

CSphString sError;
// make config
CSphConfigSection tConf;

// setup source
CSphSource_Document * pSource = ( CSphSource_Document * ) sphCreateSourceXmlpipe2 ( &tConf, fp, "xml", 2*1024*1024, false, sError );
ASSERT_FALSE ( pSource->Connect ( sError ) );
ASSERT_STREQ ( sError.cstr(), sRes );

// clean up, fp will be closed automatically in CSphSource_BaseSV::Disconnect()
SafeDelete ( pSource );
unlink ( sTmpFile.cstr() );
}


24 changes: 18 additions & 6 deletions src/sphinx.cpp
Expand Up @@ -27967,6 +27967,12 @@ struct CSphSchemaConfigurator
tCol.m_eSrc = SPH_ATTRSRC_FIELD; tCol.m_eSrc = SPH_ATTRSRC_FIELD;
} }


if ( tCol.m_sName.IsEmpty() )
{
sError.SetSprintf ( "column number %d has no name", tCol.m_iIndex );
return false;
}

if ( CSphSchema::IsReserved ( tCol.m_sName.cstr() ) ) if ( CSphSchema::IsReserved ( tCol.m_sName.cstr() ) )
{ {
sError.SetSprintf ( "%s is not a valid attribute name", tCol.m_sName.cstr() ); sError.SetSprintf ( "%s is not a valid attribute name", tCol.m_sName.cstr() );
Expand Down Expand Up @@ -28552,10 +28558,16 @@ bool CSphSource_XMLPipe2::ParseNextChunk ( int iBufferLen, CSphString & sError )
if ( m_dParsedDocuments.GetLength() ) if ( m_dParsedDocuments.GetLength() )
uFailedID = m_dParsedDocuments.Last()->m_uDocID; uFailedID = m_dParsedDocuments.Last()->m_uDocID;


sError.SetSprintf ( "source '%s': XML parse error: %s (line=%d, pos=%d, docid=" DOCID_FMT ")", if ( !m_sError.IsEmpty () )
m_tSchema.GetName(), sph_XML_ErrorString ( sph_XML_GetErrorCode ( m_pParser ) ), {
(int)sph_XML_GetCurrentLineNumber ( m_pParser ), (int)sph_XML_GetCurrentColumnNumber ( m_pParser ), sError = m_sError;
uFailedID ); } else
{
sError.SetSprintf ( "source '%s': XML parse error: %s (line=%d, pos=%d, docid=" DOCID_FMT ")",
m_tSchema.GetName(), sph_XML_ErrorString ( sph_XML_GetErrorCode ( m_pParser ) ),
(int)sph_XML_GetCurrentLineNumber ( m_pParser ), (int)sph_XML_GetCurrentColumnNumber ( m_pParser ),
uFailedID );
}
m_tDocInfo.m_uDocID = 1; m_tDocInfo.m_uDocID = 1;
return false; return false;
} }
Expand Down Expand Up @@ -28814,7 +28826,7 @@ void CSphSource_XMLPipe2::StartElement ( const char * szName, const char ** pAtt


if ( bIsAttr ) if ( bIsAttr )
{ {
if ( CSphSchema::IsReserved ( Info.m_sName.cstr() ) ) if ( Info.m_sName.IsEmpty() || CSphSchema::IsReserved ( Info.m_sName.cstr() ) )
{ {
Error ( "%s is not a valid attribute name", Info.m_sName.cstr() ); Error ( "%s is not a valid attribute name", Info.m_sName.cstr() );
return; return;
Expand Down Expand Up @@ -28881,7 +28893,7 @@ void CSphSource_XMLPipe2::StartElement ( const char * szName, const char ** pAtt


if ( !bError ) if ( !bError )
{ {
if ( CSphSchema::IsReserved ( Info.m_sName.cstr() ) ) if ( Info.m_sName.IsEmpty() || CSphSchema::IsReserved ( Info.m_sName.cstr() ) )
{ {
Error ( "%s is not a valid attribute name", Info.m_sName.cstr() ); Error ( "%s is not a valid attribute name", Info.m_sName.cstr() );
return; return;
Expand Down

0 comments on commit 3613714

Please sign in to comment.