Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore all malformed objects when ignore_malformed is true #4494

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Bug]: gradle check failing with java heap OutOfMemoryError (([#4328](https://github.com/opensearch-project/OpenSearch/
- `opensearch.bat` fails to execute when install path includes spaces ([#4362](https://github.com/opensearch-project/OpenSearch/pull/4362))
- Fixed flaky test `ResourceAwareTasksTests.testTaskIdPersistsInThreadContext` ([#4484](https://github.com/opensearch-project/OpenSearch/pull/4484))
- Fixed the ignore_malformed setting to also ignore objects ([#4494](https://github.com/opensearch-project/OpenSearch/pull/4494))

### Security
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))
Expand Down
29 changes: 18 additions & 11 deletions server/src/main/java/org/opensearch/index/mapper/FieldMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
Expand Down Expand Up @@ -268,6 +269,8 @@ public void parse(ParseContext context) throws IOException {
try {
parseCreateField(context);
} catch (Exception e) {
boolean ignore_malformed = false;
if (context.indexSettings() != null) ignore_malformed = IGNORE_MALFORMED_SETTING.get(context.indexSettings().getSettings());
String valuePreview = "";
try {
XContentParser parser = context.parser();
Expand All @@ -278,23 +281,27 @@ public void parse(ParseContext context) throws IOException {
valuePreview = complexValue.toString();
}
} catch (Exception innerException) {
if (ignore_malformed == false) {
throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id()
);
}
}

if (ignore_malformed == false) {
throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Could not parse field value preview,",
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id()
context.sourceToParse().id(),
valuePreview
);
}

throw new MapperParsingException(
"failed to parse field [{}] of type [{}] in document with id '{}'. " + "Preview of field's value: '{}'",
e,
fieldType().name(),
fieldType().typeName(),
context.sourceToParse().id(),
valuePreview
);
}
multiFields.parse(this, context);
}
Expand Down