diff options
author | Jiayu Hu <hujiayu@google.com> | 2023-09-15 11:26:48 -0700 |
---|---|---|
committer | Jiayu Hu <hujiayu@google.com> | 2023-09-15 11:36:04 -0700 |
commit | a7a951e46e76865b3f82d7538177290c99d6f8ea (patch) | |
tree | 155e68e900a1f37adf113e6f91090dfb41f63c84 /icing | |
parent | c5857eb7df5f89991f7b4949e4a1cce4c2f872f5 (diff) | |
download | icing-a7a951e46e76865b3f82d7538177290c99d6f8ea.tar.gz |
Fix the crash when a schema type gets more indexable properties than allowed
This is a cherrypick for cl/565170429.
Test: presubmits
Change-Id: I42f619cfa02d33df9026c0638f9d202e0153ad37
Diffstat (limited to 'icing')
-rw-r--r-- | icing/icing-search-engine_schema_test.cc | 20 | ||||
-rw-r--r-- | icing/schema/schema-store.cc | 6 |
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()); } } |