Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fixed #197 indexer crash on xml embeded schema with empty attribute n…
…ame; added regression to tests
- Loading branch information
Showing
with
62 additions
and
6 deletions.
-
+44
−0
src/gtests_text.cpp
-
+18
−6
src/sphinx.cpp
|
@@ -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() ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() ) ) |
|
|
{ |
|
|
sError.SetSprintf ( "%s is not a valid attribute name", tCol.m_sName.cstr() ); |
|
|
|
|
if ( m_dParsedDocuments.GetLength() ) |
|
|
uFailedID = m_dParsedDocuments.Last()->m_uDocID; |
|
|
|
|
|
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 ); |
|
|
if ( !m_sError.IsEmpty () ) |
|
|
{ |
|
|
sError = m_sError; |
|
|
} 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; |
|
|
return false; |
|
|
} |
|
|
|
|
|
|
|
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() ); |
|
|
return; |
|
|
|
|
|
|
|
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() ); |
|
|
return; |