Browse Source

Don't allow to add more than 256 fields

Add test.
That fixes #2995
alexey 3 years ago
parent
commit
a2eeedbea5
3 changed files with 57 additions and 0 deletions
  1. 5 0
      src/sphinx_alter.cpp
  2. 0 0
      test/test_266/model.bin
  3. 52 0
      test/test_266/test.xml

+ 5 - 0
src/sphinx_alter.cpp

@@ -450,6 +450,11 @@ bool IndexAlterHelper_c::Alter_AddRemoveFieldFromSchema ( bool bAdd, CSphSchema
 {
 	if ( bAdd )
 	{
+		if ( tSchema.GetFieldsCount() >= SPH_MAX_FIELDS )
+		{
+			sError.SetSprintf ( "Can not alter: index can't have more than %d full-text fields.", SPH_MAX_FIELDS );
+			return false;
+		}
 		CSphColumnInfo tField;
 		tField.m_sName = sFieldName;
 		tField.m_uFieldFlags = uFieldFlags;

File diff suppressed because it is too large
+ 0 - 0
test/test_266/model.bin


+ 52 - 0
test/test_266/test.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<test>
+
+<name>add to many ft fields to an index</name>
+
+<requires>
+	<force-rt/>
+</requires>
+
+<skip_indexer/>
+
+<config>
+searchd
+{
+	<searchd_Settings/>
+	data_dir = <data_path path="data0"/>
+}
+</config>
+
+<queries>
+	<sphinxql>
+		drop table if exists t;
+		create table t(field_0 text);
+	</sphinxql>
+	<repeat count="255" vars="i" init="1" inc="1">
+		<sphinxql>
+			alter table t add column field_<i/> text;
+		</sphinxql>
+	</repeat>
+	<sphinxql>
+		<!-- that one should fail -->
+		alter table t add column field_256 text;
+		desc t;
+	</sphinxql>
+
+	<!-- creation works ok, but let it be also here -->
+	<var name="fld"/>
+	<repeat count="257" vars="i" init="0" inc="1">
+		<var name="fld" delimiter=",">field_<i/> text</var>
+	</repeat>
+	<sphinxql>
+		drop table if exists t1;
+		create table t1(<fld/>);
+		desc t1;
+	</sphinxql>
+	<sphinxql>
+		drop table t;
+		drop table t1;
+	</sphinxql>
+</queries>
+
+</test>

Some files were not shown because too many files changed in this diff