aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiayu Hu <hujiayu@google.com>2023-09-15 20:59:50 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-09-15 20:59:50 +0000
commite4678deaff9ba9e27e403583a22b2d09de3196d0 (patch)
tree448721e9ee2269a9f4c37a09c9c040cc0a228a2c
parentcdc18a15682f75df3c872ccd7659802f3a4fa1b0 (diff)
parenta7a951e46e76865b3f82d7538177290c99d6f8ea (diff)
downloadicing-e4678deaff9ba9e27e403583a22b2d09de3196d0.tar.gz
Fix the crash when a schema type gets more indexable properties than allowed am: a7a951e46e
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/icing/+/24773477 Change-Id: I35285d67eba1dc4c78b34da87fdc8fb4e2e984f3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--icing/icing-search-engine_schema_test.cc20
-rw-r--r--icing/schema/schema-store.cc6
2 files changed, 23 insertions, 3 deletions
diff --git a/icing/icing-search-engine_schema_test.cc b/icing/icing-search-engine_schema_test.cc
index 0e88c5a..d665673 100644
--- a/icing/icing-search-engine_schema_test.cc
+++ b/icing/icing-search-engine_schema_test.cc
@@ -3131,6 +3131,26 @@ TEST_F(IcingSearchEngineSchemaTest, IcingShouldWorkFor64Sections) {
EqualsSearchResultIgnoreStatsAndScores(expected_no_documents));
}
+TEST_F(IcingSearchEngineSchemaTest, IcingShouldReturnErrorForExtraSections) {
+ // Create a schema with more sections than allowed.
+ SchemaTypeConfigBuilder schema_type_config_builder =
+ SchemaTypeConfigBuilder().SetType("type");
+ for (int i = 0; i <= kMaxSectionId + 1; ++i) {
+ schema_type_config_builder.AddProperty(
+ PropertyConfigBuilder()
+ .SetName("prop" + std::to_string(i))
+ .SetDataTypeString(TERM_MATCH_PREFIX, TOKENIZER_PLAIN)
+ .SetCardinality(CARDINALITY_OPTIONAL));
+ }
+ SchemaProto schema =
+ SchemaBuilder().AddType(schema_type_config_builder).Build();
+
+ IcingSearchEngine icing(GetDefaultIcingOptions(), GetTestJniCache());
+ ASSERT_THAT(icing.Initialize().status(), ProtoIsOk());
+ ASSERT_THAT(icing.SetSchema(schema).status().message(),
+ HasSubstr("Too many properties to be indexed"));
+}
+
} // namespace
} // namespace lib
} // namespace icing
diff --git a/icing/schema/schema-store.cc b/icing/schema/schema-store.cc
index a389d13..85ee6b6 100644
--- a/icing/schema/schema-store.cc
+++ b/icing/schema/schema-store.cc
@@ -448,7 +448,7 @@ libtextclassifier3::Status SchemaStore::InitializeDerivedFiles() {
"Combined checksum of SchemaStore was inconsistent");
}
- BuildInMemoryCache();
+ ICING_RETURN_IF_ERROR(BuildInMemoryCache());
return libtextclassifier3::Status::OK;
}
@@ -463,7 +463,7 @@ libtextclassifier3::Status SchemaStore::RegenerateDerivedFiles(
ICING_RETURN_IF_ERROR(schema_type_mapper_->Put(
type_config.schema_type(), schema_type_mapper_->num_keys()));
}
- BuildInMemoryCache();
+ ICING_RETURN_IF_ERROR(BuildInMemoryCache());
if (create_overlay_if_necessary) {
ICING_ASSIGN_OR_RETURN(
@@ -494,7 +494,7 @@ libtextclassifier3::Status SchemaStore::RegenerateDerivedFiles(
/*overlay_created=*/true, min_overlay_version_compatibility);
// Rebuild in memory data - references to the old schema will be invalid
// now.
- BuildInMemoryCache();
+ ICING_RETURN_IF_ERROR(BuildInMemoryCache());
}
}