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

[BUG] Request to index a large deeply nested doc that can potentially cause stack overflow and node to crash #5195

Closed
nkumar04 opened this issue Nov 10, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@nkumar04
Copy link
Contributor

nkumar04 commented Nov 10, 2022

Describe the bug
User with proper permission to OpenSearch endpoint can create a large deeply nested request that can potentially cause stack overflow and node to crash. For example, see the request below. Current implementation recursively goes inside each nested filed object and tries to parse it.

{
  "inner1": {
    "inner2": {
      "inner3": {
        ...
        #nested upto N (where N is very large number ~10000)
        ...
      }
    }
  }
}

To Reproduce
Steps to reproduce the behavior:
Use the python script (create_doc.py) below to generate a deeply nested doc.

import json
import sys
DEPTH=2000
n = len(sys.argv)
if n == 2:
    DEPTH = int(sys.argv[1])
obj = '{ "field": "value" }'
for i in range(DEPTH):
    field = "\"inner"+str(i+1)+"\""
    obj = "{ " + field + ": " + obj + "}"
json_doc = open("data.json", "w")
json_doc.write(obj)
json_doc.close()

Create a nested doc:
python3 create_doc.py 10000
Add the document for indexing:
curl -XPUT "localhost:9200/test-index-1/_doc/1?pretty" -H 'Content-Type: application/json' -d @data.json
Output from local run:

?  fatal error in thread [opensearch[runTask-0][write][T#2]], exiting
?  java.lang.StackOverflowError
?       at org.opensearch.common.settings.Setting.isDeprecated(Setting.java:388)
?       at org.opensearch.common.settings.Setting.checkDeprecation(Setting.java:563)
?       at org.opensearch.common.settings.Setting.getRaw(Setting.java:536)
?       at org.opensearch.common.settings.Setting.get(Setting.java:469)
?       at org.opensearch.common.settings.Setting.get(Setting.java:465)
?       at org.opensearch.Version.indexCreated(Version.java:140)
?       at org.opensearch.index.mapper.ObjectMapper.<init>(ObjectMapper.java:454)
?       at org.opensearch.index.mapper.ObjectMapper$Builder.createMapper(ObjectMapper.java:246)
?       at org.opensearch.index.mapper.ObjectMapper$Builder.build(ObjectMapper.java:224)
?       at org.opensearch.index.mapper.ObjectMapper$Builder.build(ObjectMapper.java:173)
?       at org.opensearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:551)
?       at org.opensearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:440)

Expected behavior
Exception while parsing the request doc should be handled gracefully without crashing the OpenSearch application.

Additional context
There are few settings in place to limit the number of field mappings (created manually or dynamically) and prevent documents from causing a mapping explosion. For example, INDEX_MAPPING_DEPTH_LIMIT_SETTING. Document parser parses the document and feed it to the mapper service to create or update the mapping tied to the index. Settings to limit the number of field mappings are enforced while creating or updating the mapping for index dynamically. But the prerequisite for these validation is successful completion of document parsing stage. Hence, we want to make sure that any exception at the time of parsing of a malformed document is handled gracefully

@nkumar04 nkumar04 added bug Something isn't working untriaged labels Nov 10, 2022
@nkumar04 nkumar04 changed the title Request to index a large deeply nested doc that can potentially cause stack overflow and node to crash[BUG] [BUG] Request to index a large deeply nested doc that can potentially cause stack overflow and node to crash Nov 10, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 10, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 10, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 10, 2022
@dblock dblock removed the untriaged label Nov 10, 2022
@dblock
Copy link
Member

dblock commented Nov 10, 2022

Thanks for reporting this! I see you have started on a fix, looking forward to it.

nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 30, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 30, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Nov 30, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Dec 1, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Dec 5, 2022
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Dec 5, 2022
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 4, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 4, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 4, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 5, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 5, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 5, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Jan 5, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 8, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 8, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 8, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 8, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 8, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 23, 2023
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 23, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 23, 2023
Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 pushed a commit to nkumar04/OpenSearch that referenced this issue Feb 23, 2023
shwetathareja pushed a commit that referenced this issue Feb 28, 2023
* Adding depth check in doc parser for deep nested document

Fixing the issue (#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
nkumar04 added a commit to nkumar04/OpenSearch that referenced this issue Mar 3, 2023
…-project#5199)

* Adding depth check in doc parser for deep nested document

Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
(cherry picked from commit 950b86a)
nkumar04 added a commit to nkumar04/OpenSearch that referenced this issue Mar 3, 2023
…-project#5199)

* Adding depth check in doc parser for deep nested document

Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
(cherry picked from commit 950b86a)
nkumar04 added a commit to nkumar04/OpenSearch that referenced this issue Mar 3, 2023
…-project#5199)

* Adding depth check in doc parser for deep nested document

Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
(cherry picked from commit 950b86a)
reta pushed a commit that referenced this issue Mar 3, 2023
)

* Adding depth check in doc parser for deep nested document

Fixing the issue (#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
(cherry picked from commit 950b86a)
mingshl pushed a commit to mingshl/OpenSearch-Mingshl that referenced this issue Mar 24, 2023
…-project#5199)

* Adding depth check in doc parser for deep nested document

Fixing the issue (opensearch-project#5195)

Signed-off-by: Nikhil Kumar <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants